Hello.
I'm wondering of the solution for a validation regarding this sequence.
MM/DD/YYYY - MM/DD/YYYY
How can I validate if the user input that sequence?
Thanks.
validation format
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: validation format
This will do it mostly, except there is no way to determine whether they entered MM/DD/YYYY versus DD/MM/YYYY. You'd be better off implementing a date picker, either Javascript or a simple one with dropdown boxes.
Code: Select all
$str = '02/20/1971 - 02/20/2010';
if(!preg_match('#[\d]{2}/[\d]{2}/[\d]{4} - [\d]{2}/[\d]{2}/[\d]{4}#')) {
//error
}mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: validation format
Thanks for your input AbraCadaver. This is just what I need, I'm planning to also on those options you suggest. As of now, this would fit.
Huge thanks once more.
Huge thanks once more.
Re: validation format
I tested your code once more, I think there is an error in here. It wont print anything even if I put a echo in the if.
Code: Select all
<?php
$str = '02/20/1971 - 02/20/2010';
if(!preg_match('#[\d]{2}/[\d]{2}/[\d]{4} - [\d]{2}/[\d]{2}/[\d]{4}#',$str)) {
echo "Error";
}
?>- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: validation format
That's because it matches and the ! means if not a match. Change to this and try it:
Code: Select all
$str = '02-20-1971 - 02-20-2010';mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: validation format
Thank you AbraCadaver