0

hi i a beginner in working with regular expressions i have a regular expression for email as i have copied that from some other source

(?=.[@])

it is not working i wanted to test different combinations so i m trying to match only @ value for the input field but is not working. if i write the same to the numerical values it is working in the password field

((?=.[0-9]+).{6,})

***Note:***As i am practicing application of different methods and trying to get a clear idea about regex please ignore the common ethics like the password regex i chose.

Moreover i wanted to know why this ?=. used preceding the pattern

Thanks in advance

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Jason
  • 129
  • 1
  • 5
  • 19
  • ?=. is positive lookahead – samgak May 13 '15 at 04:58
  • Thanks @samgak can you give some references to learn about the usage of regular expressions – Jason May 13 '15 at 05:16
  • 1
    You can use this to test regexes: http://www.regexr.com/ You can paste a regex in and then hover over each part with the mouse to see what it does. The cheatsheet section also gives a good summary. – samgak May 13 '15 at 05:23

2 Answers2

2

Your current regex expressions are not doing what you think:

Email:

(?=.[@])
<!-- matches a single character followed by @, e.g. a@ -->

Password:

((?=.[0-9]+).{6,})
<!-- matches a single character followed by at least 5 digits, e.g. a12345 -->

You could try using this for email: (?=.*[@].*\..*)
And this for password: ((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
1

Try this: Email validation using regular expression in JSF 2 / PrimeFaces

[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]
Community
  • 1
  • 1
Tim.Tang
  • 3,158
  • 1
  • 15
  • 18