Anyone have a good example of client side email validation working?
Anyone have a good example of client side email validation working?
bfarkas
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
There is a built-in email validator in the Editor.
https://editor.datatables.net/manual/php/validation#Strings
Thanks, but that is for the php setup which I am not using. No server here, all JavaScript client side validating.
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
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.
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
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.
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">