Thursday, 15 March 2012

php - Using the regex from valid_email method in CodeIgniter to route a URL with an email in it for email verification -



php - Using the regex from valid_email method in CodeIgniter to route a URL with an email in it for email verification -

the email verification link create validate user follows:

site_url/user@example.com/hash_to_verify

i'm trying route url 1 above activate_user method in registration controller. tried using same regex used in valid_email method in codeigniter, doesn't seem work (doesn't route activate_user method):

$route['registration/(/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix)/(:any)'] = 'registration/activate_user/$1';

1) did go wrong in route?

2) formatting url way acceptable verify emails?

thanks

$route['registration/(/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix)/(:any)']

should be:

$route['registration/([\w+-]+)(\.[\w+-]+)*@([a-za-z\d-]+\.)+[a-za-z]{2,6}/(:any)']

the entire string regex without delimiters or modifiers. putting delimiters, modifiers , using ^ , $.

i simplified regex, email validation should not done via url. instead controller should checking segment , performing validation on it. if not match redirect re-register or output error message, otherwise go on on registration.

btw don't re-invent wheel when validating email address. php has built-in validation via filter_var() function.

example:

$email = 'joe@example.com'; if (filter_var($email, filter_validate_email)) { echo 'valid'; }

php regex codeigniter url-routing

No comments:

Post a Comment