JStumpf Posted August 21, 2013 Share Posted August 21, 2013 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 More sharing options...
ThomasLewis Posted August 21, 2013 Share Posted August 21, 2013 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 More sharing options...
Impressive Posted October 23, 2015 Share Posted October 23, 2015 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. Link to comment Share on other sites More sharing options...
ThomasLewis Posted October 24, 2015 Share Posted October 24, 2015 The part of the script that needs to be altered is the part inside the quotes, not the name of the variable. var field_id_name = "Phone Number"; Should be changed to: var field_id_name = "Phone1"; Or as you have the variable name changed already: var Phone1 = "Phone1"; Link to comment Share on other sites More sharing options...
iprint2 Posted October 26, 2015 Share Posted October 26, 2015 That worked and thank you so much! Link to comment Share on other sites More sharing options...
Recommended Posts