Reputation: 5418
I want to validate a string like
Case
I have used following expression but it can validate only first two character as a Alphabet, how to validate last 2 and total number?
var re = new RegExp('^[a-zA-Z]{2}');
re.test('CC8A8');
Upvotes: 3
Views: 16293
Reputation: 3509
Below regex will help you to validate:
var re = new RegExp('^[a-zA-Z]{2}[0-9]{2}$');
Upvotes: 9
Reputation: 785058
You can use:
var re = /^[a-zA-Z]{2}\d{2}$/;
no need to use RegExp
object for this.
Upvotes: 1
Reputation: 174696
Just add the pattern to validate 2 digits at the last.
var re = new RegExp("^[a-zA-Z]{2}\\d{2}$", "m");
Upvotes: 1