|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
Validate numbers or digits only
Hello,
I have tried to get this but... $a=123.22; $b="123,23"; $c="767rrrr"; $d="é45"; $e=#10; echo (only_numbers($a))?"Valid":"Invalid"; echo (only_numbers($b))?"Valid":"Invalid"; echo (only_numbers($c))?"Valid":"Invalid"; echo (only_numbers($d))?"Valid":"Invalid"; variable $a shoud be the only one valid but it is not, it also validates $d. function only_numbers($para) { if (!ereg("[a-zA-Z,]")) { return 1 } } I have also tried other things like [[:digit:]] and [0-9] but commas and letters pass through. I just want numbers with decimal point. |
|
#2
|
|||
|
|||
|
RE: Validate numbers or digits only
how about something like
if(is_int($val) || is_float($val)) { // it's numerical } |
|
#3
|
|||||
|
|||||
|
RE: Validate numbers or digits only
or:
php Code:
|
|
#4
|
|||
|
|||
|
RE: Validate numbers or digits only
Thank you for trying, but none did work.
notePad's is_int-or-is_float version returns FALSE because the variables shown somehow are treated as string when queried or posted in a form. Gipz' more elaborated version returns all data as being invalid. The pointer $this-> should be eliminated; it is not a class (I guess..) So the function that is likely to funtion is: The problem is that this returns TRUE even for $para="é45"; or "[accented-letter]45"; or "4%5"; //any special and not-so-special chars out of the "alpha" range anywhere in the string (when capturing data it is received as STRING! Is there a way to write something like...? ...all characters out of the alpha-range; including îéç#[ (special chars)... |
|
#5
|
|||
|
|||
|
RE: Validate numbers or digits only
try:
|
|
#6
|
|||
|
|||
|
RE: Validate numbers or digits only
It works!!!
Zombies' function works perfectly for my case. THNX AGAIN! |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Validate numbers or digits only |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|