php - Form field Validation custom email requirements -
looking create form validation on email text field. have used validation ensure correct email produced.
but here looking create more custom rule allows emails ending in format .ac.uk
here user able provide university/college/instituion long last 6 characters in string = .ac.uk general format mail follows: email@university.ac.uk
solution preferably in php, looking @ employing rule using end part in statement:
^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$
making part *(\.[a-z]{2,3})
relate .ac.uk
many thanks, appreciated jeanclaude
i first run email through filter_var($email, filter_validate_email)
rather using simple regex. it's not perfect (i've found few edge cases don't validate correctly) works well. once know it's valid email address can trust substr($email, -6) == '.ac.uk'
, done it. like:
if (filter_var($email, filter_validate_email) && strtolower(substr(trim($email), -6))) === '.ac.uk') { // valid }
Comments
Post a Comment