I have a form and upon submitting it, I would like to ensure the following:
- the beginning of whatever is typed in the input field starts with
mod_ - After
mod_, only alpha numeric characters can be used.
For the first stage, I got this far:
if (preg_match('/^mod_/', $str)) {
//script goes here
}
However for the second stage, I’m not entirely sure if is the best method/works:
if (preg_match('/^mod_/[A-Za-z0-9]$/', $str)) {
//script goes here
}
I have probably made a mistake in the second stage of the preg_match(), however, if I haven’t, could someone please let me know if what I have used is ok, else what could be done to improve it.
This should do it:
The
+that I added before the$means “match the previous thing 1 or more times.” In this case, that is 1 or more ASCII characters or digits.