0

Am working on password validation , I got stuck at looking for one RegEx ,

I need a RegEx which does not allow the password to start with numbers or which allows the password to start with alphabet .

I tried few RegEx like [^0-9] , [ /[a-z][A-Z/g] ] .

Kindly help me in this .

3
  • 5
    "which does not allow the password to start with numbers" --- please don't do that. Let your users make their own decision about what to start their passwords with. By adding some weird constraints you just make passwords less memorable for users. Commented Sep 7, 2012 at 5:10
  • but this is clients requirement . Commented Sep 7, 2012 at 5:13
  • 4
    Just because a client /asks/ for something doesn't mean you can't tell them they are an idiot (in nice words). Commented Sep 7, 2012 at 5:14

2 Answers 2

1

Fairly simple, actually:

^[^0-9]

will make sure the first character is not a digit. But as zerkms notes in a comment already, you're reducing password entropy that way, thus making the system less safe, actually.

Sign up to request clarification or add additional context in comments.

3 Comments

Error: SyntaxError: unterminated regular expression literal , i got this script error when i use the above RegEx .
can you help me in fixing this .
Make sure you're adding the slashes to indicate this is a regex. i.e., yourstring.match(/^[^0-9]/)
0

This is the one you need:

^([^0-9]).*

Regex Demo

EDIT:

Javascript:

var regexmatch = /^([^0-9]).*/

if (regexmatch.test(YOUR_EXPRESSION)){ 
    // code stuff
}

2 Comments

Error: SyntaxError: unterminated regular expression literal
I just editted the answer..I me know if it works for you..@JeyRavi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.