On Input - Avoiding Infinite Loop
I have a nice routine to validate a UK phone number, but I want to update the field with the reformatted number (spaces removed) as part of the routine, which just sends me in an 'on input' infinite loop ?
Any suggestions ?
Thanks
Neil
- // Set RegEx Variable Match Strings
- UK_Phone_RX = ("^(((\+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}))?$");
- UK_Mobile_RX = ("^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$");
- // Strip out ALL spaces from the number
- e = input.Your_Phone_Number.replaceAll(" ","",false);
- Error = 0;
- // Check if Valid UK Landline
- if (!e.matches(UK_Phone_RX))
- {
- Error = 1;
- }
- // Check if Valid UK Mobile - only check if it failed the Landline test
- if (Error = 1)
- {
- if (!e.matches(UK_Mobile_RX))
- {
- Error = 1;
- }
- else
- {
- Error = 0;
- }
- }
- // Alert if number not valid
- if (Error = 1)
- {
- alert("Sorry " + e + " does not appear to be a valid phone number");
- }
- else
- {
- input.Valid_Number = true;
- }