regex - Email validation- characters length before @ and before dot -


i use following regex pattern validating email address works fine, but need validate length of characters before @, should not less 4 characters. same rule should put length of characters after @ , before dot ..

for example, email address not valid: a@b.c

however, 1 should valid: abcd@abcd.com

how can it?

here current attempt:

<ui:define name="validation-tag">     <f:validateregex          pattern="([\w\.-]*[a-za-z0-9_]@[\w\.-]*[a-za-z0-9]\.[a-za-z][a-za-z\.]*[a-za-z])*"         for="contactemailaddress" /> </ui:define> 

we can impose length restrictions using positive look-aheads anchors.

^(?=[^@]{4,}@)([\w\.-]*[a-za-z0-9_]@(?=.{4,}\.[^.]*$)[\w\.-]*[a-za-z0-9]\.[a-za-z][a-za-z\.]*[a-za-z])$ 

the ^ , $ make string match @ start , end, (?=[^@]{4,}@) make sure have @ least 4 characters before first @, , (?=.{4,}\.[^.]*$) make sure part before last . @ least 4 symbols long.

see demo


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -