Jump to content

Telephone Format Error Message


JStumpf

Recommended Posts

I have a formatted text rule for the telephone field that will format the numbers to "." instead of "-" (ie. 1.800.123.4567) as per my clients corporate standards. The format rule is also setup so they cannot enter MORE than 13 Characters (ie. 1-800-123-4567).

 

If the user enters less than the appropriate amount of numbers... the typed in data will populate as is (1.800.123.456) or (1800123456) which is not correct and it does not inform the user that the inputted data is not a valid phone number.

 

I want an error message to appear, a pop up. (Same as if you did not fill in a required field upon previewing a template) stating that they must enter 13 Characters for the phone number and not populate the incorrect/missing telephone number.

 

Any way to do this?

Link to comment
Share on other sites

You can add this to the Note section of the field in Marcom. You will need to change the field_id_name variable to match the <input id="Phone Number" part of the form field. Make sure you inspect the html so it is exactly correct.

 

<script type="text/javascript">

//This needs to match the <input id= of the field that the url is entered in.
var field_id_name = "Phone Number";


document.getElementById(field_id_name).onblur = alert_box;

function alert_box()
{
var phoneno = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;

if(!this.value.match(phoneno))
{
	alert("This is not a valid number. Example: 800-555-1234");
	this.value = "";
}
}

</script>

Link to comment
Share on other sites

  • 2 years later...

I am not able to get the script to work as suggested. Here is the script I used

<script type="text/javascript">

//This needs to match the <input id= of the field that the url is entered in.

 

var Phone1 = "Phone Number";

document;getElementByID(Phone1).onblur = alert_box;

function alert_box ()

{

var phoneno = /^\ (? ([0-9] {3})?[-. ]? ([0-9] {3}) [-. ]([0-9] {4})$/;

 

if(!this.value.match (phoneno) )

{

alert ("This is not a valid number. Example: 800-555-1234);

this.value = " ";

}

}

</script>

 

 

Also I am attaching my form fields and the note section where I pasted the script.

Formfield.jpg.7a20bce79d16fa94c74d479df331d112.jpg

Notesection.jpg.a688992deb9d8f9a11cb6e4ad1944f0c.jpg

Link to comment
Share on other sites

×
×
  • Create New...