Hi,
I'm trying to figure out how to implement a server-side validation for a zip code. Zip codes need to be 5 characters long and all digits. I thought the telephone number example would help, but it looked like that was client-side using Javascript.
I've figured out basic validation to see if something has been inputted in the textbox but don't know how to proceed further:
In addition, I'm trying to find out what it would be to validate a URL and also just to validate if the input is numeric-- no length like zip code, just check if its a number (user may enter a number with 2 digits after decimal after as well).
Thanks!
Sharat
I'm trying to figure out how to implement a server-side validation for a zip code. Zip codes need to be 5 characters long and all digits. I thought the telephone number example would help, but it looked like that was client-side using Javascript.
I've figured out basic validation to see if something has been inputted in the textbox but don't know how to proceed further:
$Zip_code= JRequest::getString('Zip_code', '', 'post');
if ( !$Zip_code) {
$messages[] = "Please enter a zip code";
}In addition, I'm trying to find out what it would be to validate a URL and also just to validate if the input is numeric-- no length like zip code, just check if its a number (user may enter a number with 2 digits after decimal after as well).
Thanks!
Sharat
Hi Sharat,
The simple way is to Google "PHP validate US zipcode". This turns up a snippet that you can use like this:
Bob
The simple way is to Google "PHP validate US zipcode". This turns up a snippet that you can use like this:
<?php
$Zip_code= JRequest::getString('Zip_code', '', 'post');
if ( !preg_match("/^([0-9]{5})(-[0-9]{4})?$/i", $Zip_code) )
return "Please enter a valid zip code";
}
?>Note this will also accept a code in 12345-1234 format. Use "/^([0-9]{5})?$/i" for just the five digit version.Bob
Thanks for the help Bob. I was able to do a similar search for URL and it works.
However, when I searched for validation on a number that could have 2 digits after the decimal (possible, but not required from the user) I'm not able to find a result. Do you have any thoughts on how that would work?
Additionally, I have my form set up so I receive emails from users when they submit information. How do I make sure that the emails are sent last (only if they pass all server-side validation)? Is there a way to do this in Chronoforms?
Thanks,
Sharat
However, when I searched for validation on a number that could have 2 digits after the decimal (possible, but not required from the user) I'm not able to find a result. Do you have any thoughts on how that would work?
Additionally, I have my form set up so I receive emails from users when they submit information. How do I make sure that the emails are sent last (only if they pass all server-side validation)? Is there a way to do this in Chronoforms?
Thanks,
Sharat
Hi Sharat,
We've done the decimal check before with JavaScript and it gets complicated quite quickly with different punctuation formats. The Regex Library will probably have what you need.
Serverside validation will return the user directly to the form if it fails so no emails will be sent.
Bob
We've done the decimal check before with JavaScript and it gets complicated quite quickly with different punctuation formats. The Regex Library will probably have what you need.
Serverside validation will return the user directly to the form if it fails so no emails will be sent.
Bob
This topic is locked and no more replies can be posted.
