Form Field Validation – UserPro Forums https://forum.userproplugin.com/forums/topic/form-field-validation/feed/ Sun, 19 May 2024 09:42:20 +0000 https://bbpress.org/?v=2.6.2 en-US https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28495 <![CDATA[Form Field Validation]]> https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28495 Tue, 18 Mar 2014 22:15:07 +0000 ali1127 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!

]]>
https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28586 <![CDATA[Reply To: Form Field Validation]]> https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28586 Wed, 19 Mar 2014 21:52:45 +0000 tpan 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,

]]>
https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28672 <![CDATA[Reply To: Form Field Validation]]> https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28672 Thu, 20 Mar 2014 10:30:39 +0000 Tomas Samot 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 😀

]]>
https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28704 <![CDATA[Reply To: Form Field Validation]]> https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28704 Thu, 20 Mar 2014 15:18:16 +0000 tpan 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.

]]>
https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28706 <![CDATA[Reply To: Form Field Validation]]> https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28706 Thu, 20 Mar 2014 15:21:51 +0000 Tomas Samot I was referring to american, not you 🙂 Canada is much better then usa 😀
And yes validation via ajax is great and easy to implement.

]]>
https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28748 <![CDATA[Reply To: Form Field Validation]]> https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28748 Fri, 21 Mar 2014 05:27:39 +0000 ali1127 @ tpan

Thanks tpan for your help! I’ll give it a shot.

]]>
https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28995 <![CDATA[Reply To: Form Field Validation]]> https://forum.userproplugin.com/forums/topic/form-field-validation/#post-28995 Sat, 22 Mar 2014 19:44:06 +0000 tpan @ali1127

no problem, happy to help, hopefully it works for you.

]]>
https://forum.userproplugin.com/forums/topic/form-field-validation/#post-44210 <![CDATA[Reply To: Form Field Validation]]> https://forum.userproplugin.com/forums/topic/form-field-validation/#post-44210 Tue, 18 Nov 2014 12:10:33 +0000 agents @tpan
Hi, where exactly should go code. that you mentioned, in functions/ajax.php? I’ve tried to implement this but still it crashes and site turns “parse error: syntax error unexpected ” and so one.

Best regards
and thank you in advance

peter

]]>
https://forum.userproplugin.com/forums/topic/form-field-validation/#post-44237 <![CDATA[Reply To: Form Field Validation]]> https://forum.userproplugin.com/forums/topic/form-field-validation/#post-44237 Wed, 19 Nov 2014 04:23:29 +0000 tpan 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

]]>
https://forum.userproplugin.com/forums/topic/form-field-validation/#post-44267 <![CDATA[Reply To: Form Field Validation]]> https://forum.userproplugin.com/forums/topic/form-field-validation/#post-44267 Wed, 19 Nov 2014 07:28:22 +0000 agents @tpan
i needed this for other use. But thank you, problem solved.

Best Regards
Peter

]]>