Legacy
Phone number validation
Advanced guide to requiring a country code in a form's phone number field when reCAPTCHA is enabled.
Last updated
Was this helpful?
Advanced guide to requiring a country code in a form's phone number field when reCAPTCHA is enabled.
This article applies to Form (Legacy). For the current form editor, see Forms.
This guide shows how to require a country code in the mobile number field of a form when reCAPTCHA is active.
You add code to the form's HTML and, if needed, adjust the regular expression that validates the string. If you used validation before activating reCAPTCHA, switch to the "submit captcha" version of the code in step 2.
$J = jQuery.noConflict();
submitForm = function(){ var jval = jValidate($('formen'),true); if(!jval){ return false; } var regEx = /^\\+\[1-9\]\[0-9\]{7,14}$/; var val = $J('input\[type=tel\]').val(); if (!val || val.match(regEx)) { const siteKey = window.\_\_RECAPTCHA\_SITE\_KEY\_\_; submitCaptchaOK(siteKey); } else { alert('Enter the mobile number with country code'); $J('input\[type=tel\]').focus(); return false; } }
Last updated
Was this helpful?
Was this helpful?

