I want to validate a string in such a way that in must have 2 hypens(-)
Strings input : (for eg)
B405Q-0123-0600
B405Q-0123-0612
R450Y-6693-11H0
R450Y-6693-11H1
I want to validate a string in such a way that in must have 2 hypens(-)
Strings input : (for eg)
B405Q-0123-0600
B405Q-0123-0612
R450Y-6693-11H0
R450Y-6693-11H1
Make use of substr_count function like this
<?php
echo substr_count( "B405Q-0123-0600", "-" )."
";
echo substr_count( "B405Q01230600", "-" )."
";
?>
Will Result
2
0
Validate like this
if(substr_count( $some_string, "-" ) == 2)
{
echo 'true';
// do something here
}else
{
echo 'false validation failed';
// some error handling
}