I use this condition to check if the value is alphanumeric values:
$value =~ /^[a-zA-Z0-9]+$/
How can I modify this regex to account for a possible dot .
in the value without accepting any other special characters?
I use this condition to check if the value is alphanumeric values:
$value =~ /^[a-zA-Z0-9]+$/
How can I modify this regex to account for a possible dot .
in the value without accepting any other special characters?
Using the posix character class, one char shorter :)
value =~ /^[[:alnum:].]+$/;
Look at perl regular expressions
\w Match "word" character (alphanumeric plus "_")
$value =~ /^[\w+.]\.*$/;
Don't forget the /i
option and the \d
character class.
$value =~ /^[a-z\d.]+$/i
If you don't want to allow any characters other than those allowed in the character class, you shouldn't use the $
end of line anchor since that allows a trailing newline. Use the absolute end-of-string anchor \z
instead:
$value =~ /^[a-z0-9.]+\z/i;