Validate A .edu Or .ac Email Address
Solution 1:
You want a regular expression.
The following pattern tests for any e-mail address ending in a top-level domain like .com, .org, .net, .biz etc.
[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)\b
You can use the preg_match function in PHP, pass this as the pattern, and just change the list of top-level domains you want to accept at the end. If the function returns 0, the address didn't validate, if it returns 1, it did match.
Regex source: http://www.regular-expressions.info/email.html
preg_match: http://php.net/manual/en/function.preg-match.php
jQuery also has a validate plugin with built-in patterns for validating e-mail addresses, but you'd need to combine this with the server-side validation in PHP for those people that have Javascript disabled.
Validate plugin: http://docs.jquery.com/Plugins/Validation/validate
Solution 2:
if( strpos($_post['email'] , '.edu' ) == true){
....
}
NOTE: the 'name' in the input field of the email address should be 'email'
It is the most simple way out there to check if ".edu" is present in that email
Post a Comment for "Validate A .edu Or .ac Email Address"