Jump to content

ereg stuff


vcphp

Recommended Posts

hi guys,

 

I'm try validating one email input, like $email = "name@sub.domain.com"; and i make that, but i see one code in the web, i i don't understand one thing.

 

what the difference between:

 

$exp =  "^[a-z0-9_\.\-]+@[a-z0-9_\.\-]+\.[a-z]{2,4}$";

 

and

 

$exp2 = "^[a-z0-9_\.\-]+@[a-z0-9_\.\-]*[a-z0-9_\-]+\.[a-z]{2,4}$";

 

 

Here is the code that i can't understand *[a-z0-9_\-]

 

Tks  ;)

 

 

Link to comment
Share on other sites

That allows for an email addres with 1 or more sub-domains.

 

The part before the asterisk (which is common to both expressions) allows for an alpha-numeric (plus '_' & '-') ending in a period. The asterisk means it can match the preceeding section 0 or multiple times.

 

However, both expressions are wrong because of several reasons:

- They do not allow upper case characters

- They would allow the domain to begin with a period or have two periods in succession

- They do not allow the plus sign ('+') in the username portion, which is a perfectly acceptable character in an email address

 

 

Here is a long, but very comprehensive, regex expression for email addresses:

 

^([a-zA-Z0-9-_\+])+([\.]?[a-zA-Z0-9-_\+])*@([a-zA-Z0-9])+([\.-]?[a-zA-Z0-9])*\.([a-zA-Z]{2,})$

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.