JavaScript - Validating Irish Phone Numbers

From All n One's bxp software Wixi

Revision as of 14:11, 23 August 2014 by Philip Lacey (talk | contribs)
Jump to: navigation, search

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.asp


This library is available to all bxp pages.


The primary new functions made available are:

  • function fn_General_ValidatePhone_Irish ( strPhoneField, blReplaceWithClean, blReplaceWithBlank )
  • function fn_General_ValidatePhone_Explicit_Irish ( strPhoneField, blIsMobile, blReplaceWithClean )
  • function fn_General_RemoveAllStrings( strString )
  • function fn_General_MatchMobilePattern( strString )


The function fn_General_ValidatePhone_Irish when supplied with the field name as a text value 'field_name', will retrieve the value and validate it.


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:

fn_General_ValidatePhone_Irish ( 'strCDA_X_field_Y_Z', true, false )


In the above function call you are required to replace the following strPhoneField and blReplaceWithClean with live data related to your form.


  • strPhoneField
    • Replace this with the strCDA_X_field_X_X id of the question you wish the validation to be performed on. This would usually be the question that you are updating at the moment


  • blReplaceWithClean
    • Replace this with either true or false
      • True, will replace the phone number entered into the script with a clean version if the number is valid i.e. 01429400 will be converted to 0035314294000ii.
      • False, will not perform the cleaning on the phone number entered if its valid i.e. 014294000 will remain 01429400


  • blReplaceWithBlank
    • Replace this with either true or false
      • True, will replace an invalid phone number with blank
      • False, will not replace an invalid phone number with blank