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

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

bfarkasbfarkas Posts: 176Questions: 45Answers: 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: 2,814Questions: 22Answers: 330

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

  • bfarkasbfarkas Posts: 176Questions: 45Answers: 0

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

  • kthorngrenkthorngren Posts: 11,025Questions: 25Answers: 2,524
    edited November 22 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: 176Questions: 45Answers: 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: 11,025Questions: 25Answers: 2,524
    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: 176Questions: 45Answers: 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.' ); } }
Sign In or Register to comment.