This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes HTML, CSS and JavaScript and the fly likes Regular Expression Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Regular Expression Help" Watch "Regular Expression Help" New topic
Author

Regular Expression Help

Alvaro Sanchez
Greenhorn

Joined: Aug 26, 2008
Posts: 2
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

Joined: Jan 10, 2002
Posts: 61066
    
  66

What have you come up with so far?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alvaro Sanchez
Greenhorn

Joined: Aug 26, 2008
Posts: 2
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 ]
 
 
subject: Regular Expression Help