Validate form fields in custom form

alt=
@dobmat
10 years ago
93 posts
Hi

How can I validate that data entered in the form fields is a email address or phone number?

Thanks.
updated by @dobmat: 08/16/14 12:41:27PM
douglas
@douglas
10 years ago
2,793 posts
If your referring to making sure what is entered into the field is an actual email address etc... I believe the Form Designer already does this for you, just select the correct validation method from the "Validation" drop down in the Form Designer when modifying/creating the field.

Hope this helps,
Douglas


--

Douglas Hackney
Jamroom Team - Designer/Developer/Support
FAQ-Docs-Help Videos
brian
@brian
10 years ago
10,148 posts
There is no core checktype support for phone numbers, but for email you can do:

if (!jrCore_checktype($email, 'email')) {
    echo "not a valid email address!";
}

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
alt=
@dobmat
10 years ago
93 posts
brian:
There is no core checktype support for phone numbers, but for email you can do:

if (!jrCore_checktype($email, 'email')) {
    echo "not a valid email address!";
}

Hope this helps!

Thanks. But this is inside the create_save function, I want within in the form itself to validate the field. For example when defining the phone number field is it possible to write a 'validate' => 'numbers only' something like this?

Thanks.
brian
@brian
10 years ago
10,148 posts
dobmat:
For example when defining the phone number field is it possible to write a 'validate' => 'numbers only' something like this?

Sure - you can use:

'validate' => 'number_nn'

for "number not negative" - however if they enter a phone number like 111-222-3333, the it will fail since '-' is NOT a number.

To do this properly you need to do it one of 2 ways:

- create a custom module provided checktype plugin
- validate it how you want it to be formatted in your create_save function.

Any other way is going to be a hack and may not work.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags