-
Hi,
Is there a way to add validation requirement to the registration fields?
For instance, if we have a phone number field, are we able to add a validation feature to make sure the user is only able add 10 digits and not more or less or letters?
Thanks!
I agree, phone validation and input mask should be built into the plugin without custom code but for now you have to use ajax validation.
Open up functions/ajax.php and add:
case ‘phone_validation’:
if ( !preg_match(“/^\d{10}$/”, $input_value) ) {
$output[‘error’] = __(‘Phone number should be 10 digits’,’userpro’);
}
break;then in userpro find your phone field and under ajax check callback (advanced) put: phone_validation
remember that when you update the plugin this will be lost so backup ajax.php.
also if you would rather have something like 999-999-9999 use this instead:
case ‘phone_validation’:
if ( !preg_match(“/\d{3}-\d{3}-\d{4}/”, $input_value) ) {
$output[‘error’] = __(‘Enter number in this format 999-999-9999,’userpro’);
}
break;hope this helps,
no it shouldn’t. America forget about yourself, not everybody lives in your 0 rights country. So you suggesting to add whole world’s phone number validation? :DDD
This is framework, so users have to create their own addons to have customizations. Impossible to create plugin that will fits everybodies needs. Few people shouts they want Lighbox..few says – please disable it.. Adding settings for every crap would slow down page loadings. So everybody have to balance. I don’t think that number validation is needed, if user dumb and can’t even enter phone correctly-this is hes problems 🙂 This is how we think about this in commom sense having part of the world 😀Hey I’m Canadian Eh! Tomas, thank you for your comments, very insightful and helpful.
To others reading this, ajax validation is pretty useful if you know the custom code, you can validate pretty much anything.
For us “Americans” the code I posted above will validate our phone numbers.
I was referring to american, not you 🙂 Canada is much better then usa 😀
And yes validation via ajax is great and easy to implement.are you trying to validate phone numbers? if so, this is now built in:
http://userproplugin.com/userpro/forums/topic/new-update-available-v1-0-86/
however here is the info:
open: functions/ajax.php
find this:
case ‘username_exists’:
if (username_exists($input_value)){
$output[‘error’] = __(‘Username already taken.’,’userpro’);
} else if ( !preg_match(“/^[A-Za-z0-9_]+$/”, $input_value) ) {
$output[‘error’] = __(‘Illegal characters are not allowed in username.’,’userpro’);
}
break;and right underneath add:
case ‘phone_validation’:
if ( !preg_match(“/\d{3}-\d{3}-\d{4}/”, $input_value) ) {
$output[‘error’] = __(‘Enter number in this format 999-999-9999,’userpro’);
}
break;**make sure to enter phone_validation under the ajax callback
@tpan
i still have a question. I succesfully implemented validation form my field in profile edition. I ve put code like this:case ‘pin_validation’:
if ( !preg_match(“/^\d{4}$/”, $input_value) ) {
$output[‘error’] = __(‘PIN has to have 4 digits’,’userpro’);
}
break;This works “fine” (of course i put pin_validation in ajax check callback) but this validation works very slow in comaprison to password validation. For ex if i put too short password and save profile it will communicate immediately that password is incorrect and profile won’t save. Different is for my pin validation – it takes about 2 seconds to communicate that something is wrong. In that time i can save profile ommitting this restriction because it is to slow. Maybe you know any sollution to this issue?
Is there a way my addition to side validation can survive between updates of the plugin? Can I use some hook to add my validation without touching plugin’s ajax.php?
thanks
Found an answer to my own question: just take a look at this
make custom ajax callbacks survive to plugin updates: RESOLVED
You must be logged in to reply to this topic.