
mhx
Enthusiast
Oct 9, 2001, 7:09 AM
Post #9 of 9
(1614 views)
|
|
Re: Help In Checking content........
[In reply to]
|
Can't Post
|
|
You're looking for either
$mystring =~ /^[0-9.]*$/; or The first one checks if there are only digits or the decimal point between the beginning (^) and the end ($) of the string. The second one checks if the string does _not_ (!~) contain any character that is not ([^) a digit or a decimal point. If you additionally would want to disallow empty strings and multiple decimal points and allow leading or trailing whitespace, you should use:
$mystring =~ /^\s*(\d+(?:\.\d*)?)\s*$/; This will additionally put the number itself into the variable $1. You could also think of allowing only a certain number of digits before and after the decimal point. Say you would want to have 1 to 5 digits before and 0 to 2 digits after the decimal point, try:
$mystring =~ /^\s*(\d{1,5}(?:\.\d{0,2})?)\s*$/; This again will leave the number in $1. Now, this has become a quite complex regex, so I hope you're able to follow. Perhaps you can reuse any of the above regexes for your purposes. -- Marcus
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= ($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"
|