I am a learner in java script currently I am going through the regular expression for validating the password field, I want my password field to contain characters and only one number in any place of the string,
I tried the following regular expression it checks for at-least one number and one character in the string
^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$
Can anyone help me!
All you need is adding a lookahead at the start:
^(?=\D*\d\D*$)[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$
The lookahead makes sure there is zero or more nondigits followed by a digit and zero or more nondigits up to the end of string.
Use this RE