== 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.
https://ww3.allnone.ie/library/javascript/fn_javascript_general.aspjs
When you want a question within a bxp form to be validated by the Phone number function simply edit the question and copy the following line into the questions JavaScript onChange setting, once you have modified the below line to suit your form:
<syntaxhighlight lang="JavaScript">fn_General_ValidatePhone_Irish ( strPhoneField'strCDA_X_field_Y_Z', blReplaceWithClean true, false )</syntaxhighlight>
*** 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>
[[Category:Module Specific:Form Management]]
[[Category:Topic:JavaScript]]