• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular Expression Help

 
Alvaro Sanchez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create a regular expression that does the following:

ABC1234567890

It needs to verify that the first 3 or 4 (fourth letter is optional) digits are letters (no special characters, no numbers) and the following digits are only numbers on a range from 7 to maximum 10 digits.

I'm close but i can't quite get what I want yet.

Any help appreciated, thanks!!!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65119
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you come up with so far?
 
Alvaro Sanchez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to mention all this is inside a 'keyup' event on mootools, so it checks as the user is typing the info into the form.

I got what I wanted here is the solution, it may help other user:

if(lic_pre2.length < 3){
var regex = '^([A-Z]*)$';
var regexp = new RegExp(regex);
var licRegExp = regexp.test(lic_pre2);
if (licRegExp == false){
//Print your error here
}
}else{
var regex2 = '^([A-Z]{2,3}[0-9]{0,10})$';
var regexp3 = new RegExp(regex2);
var licRegExp2 = regexp3.test(lic_pre2);
if (licRegExp2 == false){
//Print error here
}
[ August 26, 2008: Message edited by: Alvaro Sanchez ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic