Phone Validation?
-
Hello all,
I’m using Brilliant Web-to-Lead for Salesforce and need to validate phone numbers to legitimate formats to keep our data clean.
I’m trying to usesfwp2l_validate_field
but all I’ve done so far is break the form. Anyone have a solution for validating phone numbers with this plugin?This is the HTML for the input area.
<input type="text" placeholder="" value="" id="sf_phone" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required required" name="phone">
This is what I’ve scratched together so far as a solution attempt after reading through some documentation and a lot of stackoverflow.
add_filter('sfwp2l_validate_field', 'validatePhoneNumber', 10, 4); function validatePhoneNumber($phone) { $dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); // $phone = $xpath->query('//input[id="sf_phone"]'); $phone = $xpath->evaluate('string(//input[@id="sf_phone"])') // $phone = '(123) 458-1542'; if (preg_match('~^\(*\+*[1-9]{0,3}\)*-*[1-9]{0,3}[-. /]*\(*[2-9]\d{2}\)*[-. /]*\d{3}[-. /]*\d{4} *e*x*t*\.* *\d{0,4}$~', $phone)) { echo "Matched: $phone"; } }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Phone Validation?’ is closed to new replies.