validation - 4 Digit Pin Regex -



validation - 4 Digit Pin Regex -

using jquery bootstrapvalidator , trying add together additional validation 4 digit pin financial app.

so have gotten far making sure user's input has 4 digits , numeric.

/^\d{4}$/

now trying next additional regex validations , stuck. help appreciated.

make sure 4 digits aren't same (ie. 1111 or 9999)

not sequential (ie. 1234, 6789)

not birth year. simplify, excluding number starts 19 or 20 (ie. 1986, 2004).

thanks in advance help.

your first , 3rd constraints easy translate regex:

class="lang-none prettyprint-override">^(?!(.)\1{3})(?!19|20)\d{4}$

here, used 2 negative lookaheads, 1 each constraint.

however, non-sequential constraint, while possible, unreasonably convoluted regex handle.

here, decide if it's worth pain:

class="lang-none prettyprint-override">^(?!(.)\1{3})(?!19|20)(?!0123|1234|2345|3456|4567|5678|6789|7890|0987|9876|8765|7654|6543|5432|4321|3210)\d{4}$

regex validation

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -