wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 60763
    
  65

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regular Expression Help
 
Similar Threads
how to remove the [[ from arraylist
Regular Expression for any number
Regular expression to check for specific special characters (any repitition) and 0 to 9 numbers
Regular expression - matching on full stop
JavaScript+Regular Expression Problem