Invalid quantifer error using Regular Expression (UK Telephone numbers)

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2011-01-10T16:49:43Z Indexed on 2011/01/10 16:53 UTC
Read the original article Hit count: 205

HI all,

as per the title I am getting the error "Invalid Quantifier"

Trying to match this reg ex:-

^(((+44\s?\d{4}|(?0\d{4})?)\s?\d{3}\s?\d{3})|((+44\s?\d{3}|(?0\d{3})?)\s?\d{3}\s?\d{4})|((+44\s?\d{2}|(?0\d{2})?)\s?\d{4}\s?\d{4}))(\s?#(\d{4}|\d{3}))?$

Infact ive tried a few UK telephone number regex's from the regex librairy but im getting the same error all the time. If anyone can help id be much appreciative!

Just for info, im using the jQuery form validation librairy, and here is my code: -

$(document).ready(function(){

//Set Fields to be validated
$("#EventForm").validate();
$( "#StartDate" ).datepicker();
$( "#EndDate" ).datepicker();

//Add Postcode Regex Method to Validator Function
$.validator.addMethod(
 "postcode",
 function(value, element, regexp) {
  var check = false;
  var re = new RegExp(regexp);
  return this.optional(element) || re.test(value);
 },
 "Please enter a valid postcode."
);

//Add UK Telephone number Regex Method to Validator Function
$.validator.addMethod(
 "telephone",
 function(value, element, regexp) {
  var check = false;
  var re = new RegExp(regexp);
  return this.optional(element) || re.test(value);
 },
 "Please enter a valid UK telephone number in the format - 01856 666666."
);

//Add Postcode Regular Expression Rule to Postcode Field
$("#EventPostcode").rules("add", { postcode: "^([a-zA-Z]){1}([0-9][0-9]|[0-9]|[a-zA-Z][0-9][a-zA-Z]|[a-zA-Z][0-9][0-9]|[a-zA-Z][0-9]){1}([        ])([0-9][a-zA-z][a-zA-z]){1}$"});
$("#EventTelephoneNo").rules("add", { telephone: "^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$"});

});

Many thanks

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery