I actually have two questions but they are almost the same thing.
no1, I want to use PHP to check if a variable contains anything that is not a forward slash or a number, I am aware that I can use strpos()
for this but if I do something like
if (strpos($my_variable, "/")) {
if (1 === preg_match('~[0-9]~', $string)) {
//do something
}
}
the above code first if statement checks if the variable contains forward slash then the next checks if the variable contains letters, but if someone types something like 'asdfgfds2345/' as their date of birth it will go through because the string contains a forward slash and numbers but I what my PHP script to do something like this
if(/*my_variable contains letters,special characters and any other thing that is not a number or a forward slash*/){
do something}
next question: I want to use PHP to check if a variable contains anything that is not a lowercase letter, an underscore or a hyphen, I am also aware that I can use strpos()
for this but if I can't keep doing something like this something like this
if (strpos($my_variable, "/")) {
//redirect
} else {
if (strpos($my_variable, "?")) {
//redirect
} else {
if (strpos($my_variable, "$")) {
//redirect
} else {
//do something
}
}
}
if I try to do the above it will take me a long time to finish this page so is there a way that I can do this
$chars = "$""#""/""*";
if ($myvariable contains any of the letters in $char){
//do something
}
I know that the above code is wrong in all ways but I am just trying to show you what I want to achieve
thanks in advance