Link to home
Start Free TrialLog in
Avatar of Bishork
Bishork

asked on

Regular expressions help - how to disallow two characters to be next to one another

email validation checker -

I have

/^[a-z0-9]{1,}([a-z0-9_-]|\.(?!\.))+@[a-z0-9]{1,}([a-z0-9]|\.(?!\.)|\-(?!\-)){1,}[a-z0-9]+\.[a-z0-9]{2,6}$/i;

I want to disallow joe@j-.-d.com or joe@j.-.d.com
and make this validator even better

thanks

Avatar of Bishork
Bishork

ASKER

i found
^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$

online which does not allow -. and .- together but I'm not sure why or how to integrate it into my own

any help would be appreciated.  thanks!
SOLUTION
Avatar of MMDeveloper
MMDeveloper
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry for the lack of explanation.

The function looks at all the entries in the array, and checks each one for a match within the target string. When it finds a sequence that exists in the target string, it stops looking and returns a boolean answer..

false = no matches
true = has a disallowed sequence
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bishork

ASKER

Hey Roba,

Ok that makes sense now.

Now I have

/^[a-z0-9]+([a-z0-9]|[._-](?![._-]))+@[a-z0-9]{1}([a-z0-9]|[-](?![.-])){1}([a-z0-9]|[.-](?![.-]))+\.[a-z0-9]{2,6}$/i

I wanted to make it so you could not have joe@j.com, joe@j-.com, joe@joe-.com.  I used {1} to make the first two sets after the @ sign be for the first two characters you put in, then it can start accepting both periods and dashes.  

You can still pass through a jeo@e-d.e.e.e.e.com

Is there a way I can limit the number of periods allowed in the domain, before the .xxx.  I think you should only be able to have 1 right?  joe@joe.ir.com, or maybe 2 (can you have jack@john.co.ur.com

Thanks
Avatar of Bishork

ASKER

hmm but now with what i just pasted above, test@ab.com doesn't work

Avatar of Bishork

ASKER

ok i guess i want to make sure i say that, you have to have 1 character from a-z 0-9 after the @ sign, then after that you can only have a period if you have at least 2 chars from a-z 0-9, but the problem i run into is that you should be able to have a hyphen after only having 1 character from a-z 0-9

joe@f-f.com is ok, joe@j.com is not ok
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bishork

ASKER

I think I finally got it w/ /^[a-z0-9](([_\.\-]?[a-z0-9]+)*)@([a-z0-9])+([\-]?[a-z0-9]+)(([\.\-]?[a-z0-9]+)*)\.([a-z]{2,})$/i

now I want to create a regular expression that allows any character.
I want j$^^$j@j#$j.com to pass this test, basically allowing any character between the first and last letter in the local and domain portion.

/^[a-z0-9]+???????[a-z0-9]+@[a-z0-9]+?????.([a-z]{2,})

I am trying to have it pass a form test first, then if you fail this test you'll get a message saying your email is of invalid form, then if you pass this test i'll run the more comprehensive check and tell you that you cannot have invalid characters.  (not my idea)

i posted a new question