It’s important to do form validation for obvious reasons. This is an implementation of an email checker that uses php regular expressions, and a little bet if pizzaz with asynchronous javascript and xml, or AJAX.
A quick rundown of how this works is:
- You type in a string
- You hit submit
- The data is transfered asynchronously (without refreshing the page) to the server
- The server checks to see if the email is valid or invalid
- If it’s valid it tells you so, as well as if it’s not
The guts of the script are here:
if (eregi("^[a-zA-Z0-9_-.+]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-_.]+$",$email)) {
//return confirmation that it worked
}
else {
//return that it didn't work
}
Basically, it checks to see if there’s either a lowercase or uppercase a-z or 0-9 or an underscore, or a dash, or a period before the @ sign ([a-zA-Z0-9_-.+]+@). Then after the @ sign it checks for the same thing except for the period and the underscore up until another dot. After that dot it checks once again for the same charachters as the first set.
Hopefully this helps someone. If you have any questions feel free to email me at “howe -dot- jon -at- gmail -dot- com” and I’ll help you however I can.
Later,
Jon Howe