The Phone Number field type does not validate for numbers.
So it is working as it should.
You will need to write your own validation code for that field.
Thanks for the link. Where would I add this code?
You can try in bp-custom.php or child theme’s functions.php. If not sure about files then use this plugin https://wordpress.org/plugins/code-snippets/ to add snippets.
Thanks
I added the following code to the bp-custom.php file but unfortunately it did not work.
<?php
$(document).ready(function() {
$('#field_29').blur(function(e) {
if (validatePhone('field_29')) {
$('#spnPhoneStatus').html('Valid');
$('#spnPhoneStatus').css('color', 'green');
}
else {
$('#spnPhoneStatus').html('Invalid');
$('#spnPhoneStatus').css('color', 'red');
}
});
});
function validatePhone(field_29) {
var a = document.getElementById(field_29).value;
var filter = /^[0-9-+]+$/;
if (filter.test(a)) {
return true;
}
else {
return false;
}
}
?>
Hi,
This is jquery code. Please remove it from there and use this plugin https://wordpress.org/plugins/custom-css-js/. Add a new js code and then paste this code.
Thanks
I tried this as well but it did not work.
Is there any reason that The Phone Number field type does not validate phone numbers?
Hi,
Please replace all the ‘$’ with ‘jQuery’ save the js code and then on frontend open browser console(press ctrl+shift+I if you are on chrome) and then check if there is any error in the console.
Thanks
I updated the code with what is below but it still is not working.
`jQuery(document).ready(function() {
jQuery(‘#field_29’).blur(function(e) {
if (validatePhone(‘field_29’)) {
jQuery(‘#spnPhoneStatus’).html(‘Valid’);
jQuery(‘#spnPhoneStatus’).css(‘color’, ‘green’);
}
else {
jQuery(‘#spnPhoneStatus’).html(‘Invalid’);
jQuery(‘#spnPhoneStatus’).css(‘color’, ‘red’);
}
});
});
function validatePhone(field_29) {
var a = document.getElementById(field_29).value;
var filter = /^[0-9-+]+jQuery/;
if (filter.test(a)) {
return true;
}
else {
return false;
}
}