Posts

Showing posts with the label regex validation

Regex password validation in javascript

In this first example, the password must be at least 8 characters long and start and end with a letter.  var  re = /^[A-Za-z]\w{6,}[A-Za-z]$/; if  (!re.test(myString)) { alert( "Please enter a valid password!" ); } In this second example, the password length doesn't matter, but the password must contain at least 1 number, at least 1 lower case letter, and at least 1 upper case letter.  var  re = /^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$/ if  (!re.test(myString)) { alert( "Please enter a valid password!" ); } Password Regular Expression Pattern is as follows: ( ( ?= . * \d ) ( ?= . * [ a - z ] ) ( ?= . * [ A - Z ] ) ( ?= . * [ @#$ % ] ) . { 6 , 20 } ) Explanation : ( # Start of group ( ?= . * \d ) # must contains one digit from 0 - 9 ( ?= . * [ a - z ] ) # must contains one lowercase characters ( ?= . * [ A - Z ] ) # must contains one uppercase characters ( ?= . * [ @#$ % ] ) # must contains one special symbols i...