permaculture playing cards
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Regular Expression Help" Watch "Regular Expression Help" New topic

Regular Expression Help

Alvaro Sanchez

Joined: Aug 26, 2008
Posts: 2
I'm trying to create a regular expression that does the following:


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

Joined: Jan 10, 2002
Posts: 63349

What have you come up with so far?

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

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
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:
subject: Regular Expression Help
It's not a secret anymore!