regex - verify emails in PHP -


i tried php regex verify emails, such /^[_a-z0-9-]+(\.[_a-z0-9-])*@[a-z0-9-]+(\.[a-z0-9-])*(\.[a-z]{2,4})$/. know not correct way validate emails, abc@abc.abc correct in regex.

do need enumerate domain name suffixes?

i happened know in php filter_var function can verify emails, filter_var('abc@abc.abc', filter_validate_email) correct.

what theory of filter_validate_email in php source code? or can tell me better way verify emails?

thanks much!

function php_filter_validate_email logical_filters.c used check.

it tests email against following regex /^(?!(?:(?:\\x22?\\x5c[\\x00-\\x7e]\\x22?)|(?:\\x22?[^\\x5c\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5c[\\x00-\\x7e]\\x22?)|(?:\\x22?[^\\x5c\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2a\\x2b\\x2d\\x2f-\\x39\\x3d\\x3f\\x5e-\\x7e]+)|(?:\\x22(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|(?:\\x5c[\\x00-\\x7f]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2a\\x2b\\x2d\\x2f-\\x39\\x3d\\x3f\\x5e-\\x7e]+)|(?:\\x22(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|(?:\\x5c[\\x00-\\x7f]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:ipv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:ipv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/id , maximum length of 320 characters.

also comment source:

/* * regex below based on regex michael rushton. * however, not identical. changed consider routeable * addresses valid. michael's regex considers a@b valid address * conflicts section 2.3.5 of rfc 5321 states that: * * resolvable, fully-qualified domain names (fqdns) permitted * when domain names used in smtp. in other words, names can * resolved mx rrs or address (i.e., or aaaa) rrs (as discussed * in section 5) permitted, cname rrs targets can * resolved, in turn, mx or address rrs. local nicknames or * unqualified names must not used. * * regex not handle comments , folding whitespace. while * technically valid in email address, these parts aren't * part of address itself. * * michael's regex carries copyright: * * copyright © michael rushton 2009-10 * http://squiloople.com/ * feel free use , redistribute code. please keep copyright notice. * */ 

this enough of real world emails. more details check out question: using regular expression validate email address


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -