Changes

JavaScript - Validating Irish Phone Numbers

1,293 bytes added, 19:32, 10 September 2014
no edit summary
== Overview ==
 
Validating Irish Phone numbers in bxp software (bxp) is very easy thanks to a piece of custom JavaScript developed and available through the fn_javascript_general.js library.
*** True, will replace an invalid phone number with blank
*** False, will not replace an invalid phone number with blank
 
 
 
== Extended application ==
 
 
To save yourself even more work in a bxp Form and just tidy up what has been data entered by the user you could apply the following:
 
In the onChange of the field you put the following, changing strCDA_X_field_0_Y to the field you want to validate.
 
<syntaxhighlight lang="JavaScript">
fn_MyCustomValidatePhone('strCDA_X_field_0_Y');
</syntaxhighlight>
 
 
In the onLoad of the Form, you build the MyCustomValidatePhone
 
<syntaxhighlight lang="JavaScript">
 
//One potential way of managing your phone number field
function fn_MyCustomValidatePhone( strName ){
 
//Firstly get the object to work on which has the phone number
var objField = document.getElementById(strName);
 
//Now we validate the number, but we do not do replacements
var blResult = fn_General_ValidatePhone_Irish ( strName, false, false );
//If the number is valid
if (blResult == true){
//Clean out all the non-number values
objField.value = fn_General_RemoveAllStrings(objField.value);
}
else {
 
// However you want to handle an error
// We have an error and the user cannot continue till its fixed
alert ( 'Not a valid number' ); // Error message to the user
objField.focus(); // Put the cursor back in the box to fix it.
 
}
}
 
</syntaxhighlight>
7,528
edits