Following is the requirement of field value should be - else it should generate an error

Format to be only 9 characters with 2 letters, followed by 6 numbers, followed by one letter

e.g. 'AB332211C'

Any else value should generate an error message using JavaScript. Can anyone help me in creating regex expression for this.

EDITS : Till yet I am done with this : Help to improve the same

    var myAssumption = /^\d{2}[a-zA-z] \d{6}[0-9]\d{1}[a-zA-z]$/;

Following links might help in answering : http://www.java2s.com/Code/JavaScript/Form-Control/Mustbeatleast3charactersandnotmorethan8.htm

Examples :

 // Common regexs
  var regexEmail = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
  var regexUrl = /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
  var regexDate = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
  var regexTime = /^([1-9]|1[0-2]):[0-5]\d$/;
  var regexIP = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
  var regexInteger = /(^-?\d\d*$)/; **

strong text**


1 Answer 1


Following Regular Expression worked for me -


Start - /

Handle spaces(TRIM) - \b

First 2 letters - [A-z]{2}

Followed by 6 Numbers - [0-9]{6}

End with 1 letter - [A-z]{1}$/

Hope this explanation will someone in future. Refere site : Learn Regular Expressions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.