Home > Software engineering >  Check if the word matches the required parameters
Check if the word matches the required parameters

Time:08-12

PHP 7.4. How can I check if a word has the following form -> #tag. Here the 'tag' cannot contain any characters, only letters and numbers. The # must be present at the beginning of the word

CodePudding user response:

Maybe this one

if (preg_match('/^#[a-zA-Z0-9] $/', $a)) {
    echo "Valid";
} else {
    echo "NOT valid";
}
  • Related