Hi Everyone, I am trying to allow only numbers and dashes into one of my text inputs on a form.
For example: 1-1, 1-0, 2-3 etc
And I have the following to validate numbers only
function validate_cscore($variable) {
return is_numeric($variable);
}
the above works great with the following error checking
if(!validate_cscore($cscore))
{
$hint = 'Invalid Mobile Number';
registerError( $hint, $hint, $error_title, '<p><font color="#ffffff"><strong>Invalid correct score detected</strong></font></p>' );
$b1=false;
}
I started doing some digging around and found the following to allow me to add the ability to use dashes
$csValid = array('-');
With the following error message
if(!ctype_alnum(str_replace($csValid, '', $cscore))) {
$hint = 'Name';
registerError( $hint, $hint, $error_title, '<p><font color="#ffffff"><strong>Correct score format is 1-1, 2-0, 2-1 format</strong></font></p>' );
$b1=false;
}
The above allows 1-a, b-2, 3-c etc
But get the error message "invalid correct score" error message as there is a dash in my in my input as 1-1, 2-0, 2-1 etc
How can I ensure a user enters the correct score format, but also check for instances of 1 a, 2-a, a-1 etc
Thanks in advance everyone.