Javascript Email Validator
A simple JavaScript function that tests the validity of an email in a form or other input.
1 2 3 4 | function checkemail(e) { var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; return filter.test(e); } |
The function simply return a true or false depending on the the input.
It’s important to note that having only a javascript validator for forms is not secure. There many tools out there that let users edit the DOM and they could simply turn off your validator. Make sure to have both front end (javascript) and backend (PHP, ASP, ect.) validators for your forms. It makes the world happy.
June 29th, 2009 | Javascript |