More than 1 Field with min/max character that accept only digits
-
Hi –
I need to be able to have several fields that have minlength and maxlength and ONLY allow digits 0-9.
I need it for multiple tel fields and multiple zip code fields on the same form.
The tel fields I want exactly 10 digits and the zip code I want exactly 5 digits.I tried a few different ways of doing this but it only works for one field. the rest of the fields it does not work.
Here’s the closet I got with the tel field:
Form tag: [tel* minlength:10 maxlength:10 phys-phone class:wpcf7-numbers-only-all]
2nd Forem Tag: [tel* minlength:10 maxlength:10 vet-phone class:wpcf7-numbers-only-pet]And in fucntions.php:
`/**
* CF7: Numbers Only Validation – only for PET !!!
* Validate the input fields with CSS class .wpcf7-numbers-only-pet to allow numbers only.
*/add_action( ‘wp_footer’, ‘wpcf7_input_numbers_only_pet’);
function wpcf7_input_numbers_only_pet() {
echo ‘
<script>
onload = function(){
var ele = document.querySelectorAll(\’.wpcf7-numbers-only-pet\’)[0];
ele.onkeypress = function(e) {
if(isNaN(this.value+””+String.fromCharCode(e.charCode)))
return false;
}
ele.onpaste = function(e){
e.preventDefault();
}
}
</script>
‘;
}/**
* CF7: Numbers Only Validation – all BUT Pets!!!
* Validate the input fields with CSS class .wpcf7-numbers-only-all to allow numbers only.
*/add_action( ‘wp_footer’, ‘wpcf7_input_numbers_only_all’);
function wpcf7_input_numbers_only_all() {
echo ‘
<script>
onload = function(){
var ele = document.querySelectorAll(\’.wpcf7-numbers-only-all\’)[0];
ele.onkeypress = function(e) {
if(isNaN(this.value+””+String.fromCharCode(e.charCode)))
return false;
}
ele.onpaste = function(e){
e.preventDefault();
}
}
</script>
‘;
}The above code is not working for the “ONLY for Pets” but is for the “all BUT Pets”
When say it is not working I mean it allows for letters and other characters as well as numbers 0-9 (I only want numbers 0-9) but it is limiting with min and max lengths (only allows 10 digits.Hoping that whatever the solution is, it will work for the zip code field as well.
Thanks in advance for any help you can provide!The page I need help with: [log in to see the link]
- The topic ‘More than 1 Field with min/max character that accept only digits’ is closed to new replies.