Как сделать preg_match для функции? PHP [дубликат] ⇐ Php
-
Anonymous
Как сделать preg_match для функции? PHP [дубликат]
I am trying to make a function that checks if a string is valid or not, meaning that if a user inputs 'hi,' it wouldn't work as there is a comma (the string doesn't allow any special characters). I am trying to echo the function but the output is not what I expected.
For my output, I was expecting it to print "Invalid characters. Please resubmit form.
." But the actual output just printed 'hsfsd,'.
Help would be very much appreciated!!!
function validString($var, $min=0, $max=1000){ $return = 'Return to PerformerDetail.html
'; //Checking if variable exists// if(empty($var)){ echo $return; exit("Invalid input. Please resubmit form."); //End function } if (is_numeric($var)){ echo $return; exit("Invalid input. Please resubmit form."); //End function } //Checking if any special characters are present// if (preg_match('/[\'^£$%&*()}{@#~?>
Источник: https://stackoverflow.com/questions/781 ... nction-php
I am trying to make a function that checks if a string is valid or not, meaning that if a user inputs 'hi,' it wouldn't work as there is a comma (the string doesn't allow any special characters). I am trying to echo the function but the output is not what I expected.
For my output, I was expecting it to print "Invalid characters. Please resubmit form.
." But the actual output just printed 'hsfsd,'.
Help would be very much appreciated!!!
function validString($var, $min=0, $max=1000){ $return = 'Return to PerformerDetail.html
'; //Checking if variable exists// if(empty($var)){ echo $return; exit("Invalid input. Please resubmit form."); //End function } if (is_numeric($var)){ echo $return; exit("Invalid input. Please resubmit form."); //End function } //Checking if any special characters are present// if (preg_match('/[\'^£$%&*()}{@#~?>
Источник: https://stackoverflow.com/questions/781 ... nction-php
Мобильная версия