JavaScript - error - Asked By basil on 22-Dec-10 02:15 AM

whats wrong in the below code

var phoneRegEx = "^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$";

if (!_txtPhoneno.match(phoneRegEx ))
{

alert("Enter a valid phone number.");

return false;

}

im getting an error as



Microsoft JScript runtime error: Unexpected quantifier

pradeep joshi replied to basil on 10-Jan-11 06:34 AM


   Hi,
   
    Microsoft JScript runtime error: Unexpected quantifier

    this error tells that, When composing your regular expression search pattern, you created a pattern element with an illegal repetition factor. For example, the pattern
              /^+/
  is illegal because the element ^ (beginning of input) cannot have a repetition factor. The following elements that cannot have repetition factors.   

    ^, +, *, $, \b, \B, ?, {n}, {n,}, {n,m} 
 
    where {n} for  n repetitions
            {n,} for  n or more repetitions
        {n,m} for From n to m repetitions, inclusive 

  
  Thanks
   hope this will help you