Anyone have a good example of client side email validation working?

Anyone have a good example of client side email validation working?

bfarkasbfarkas Posts: 181Questions: 48Answers: 0

I've tried a couple of regex things online but can't seem to get working with datatables well. Anyone have an example to reference? Client side/javascript application.

This question has accepted answers - jump to:

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    There is a built-in email validator in the Editor.
    https://editor.datatables.net/manual/php/validation#Strings

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    Thanks, but that is for the php setup which I am not using. No server here, all JavaScript client side validating.

  • kthorngrenkthorngren Posts: 21,352Questions: 26Answers: 4,955
    edited November 2020 Answer ✓

    This looks like an interesting solution - haven't tried it:
    https://www.w3resource.com/javascript/form/email-validation.php

    If this doesn't help then maybe a small test case showing us what you are doing will help us understand the problem you are having.

    Kevin

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    Yeah, this is the technique I was trying but it was also showing false...I think I had a thought in the shower though why so am going to give it a shot again and see if that fixes. Either way will circle back with an example.

  • kthorngrenkthorngren Posts: 21,352Questions: 26Answers: 4,955
    Answer ✓

    I tried the regex presented in the link I gave and it seems to not work as the author expects. I used https://regex101.com to test it here:
    https://regex101.com/r/wV0Pr2/1

    It finds he first three valid addresses but it also finds some of the invalid addresses.

    This is a good site to test your regex expressions. If you find others of interest you can just paste them into regex101 to test.

    Kevin

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    Yeah, all sorts of regex out there for different levels of checking. I am keeping it simple, and the issue I was running into last night was I was stupid. I was calling the field to check, but not the field.val to get its value to check, so everything was always false.....stupid me. Ended up doing the below in my validation checks which is working well.


    var pEmailVal = this.field( 'personal_email' ).val(); var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; var pEmailReal = re.test(pEmailVal.toLowerCase()); if ( ! pEmail.isMultiValue() ) { if ( pEmailVal.length > 0 && ! pEmailReal ) { pEmail.error( 'This is not a valid email address.' ); } }
  • evanmirkevanmirk Posts: 2Questions: 0Answers: 0
    edited January 2022

    The fully RFC 822 compliant regex is inefficient and obscure because of its length. Fortunately, RFC 822 was superseded twice and the current specification for is RFC 5322. RFC 5322 leads to a regex that can be understood if studied for a few minutes and is efficient enough for actual use.

    If you use HTML5, use this code:

    <input type="email" name="email" required placeholder="Enter a valid email address">

    Edited by Colin - link removed.

Sign In or Register to comment.