Super2 Posted November 3, 2006 Share Posted November 3, 2006 in some of the form`s fields entries are numbers and if they are not - returns alert mesage or some message??Does someone have any idea?Sry about the English :) (if there are any mistakes ) Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted November 3, 2006 Share Posted November 3, 2006 You can check if a variable contains only numbers in several ways:[b]is_numeric()[/b] method[code]<?php$foo = 20 // <== your variableif( is_numeric($foo) ){ echo 'Variable is a number.';} else { echo 'Variable is NOT a number';}?>[/code][b]Regular Expression[/b][code]<?php$foo = 20;if( preg_match('/^[0-9]$/', $foo)){ echo 'Variable is a number.';} else { echo 'Variable is NOT a number';}?>[/code]I'm assuming that you'll eventually want to check other fields that may not be numbers, so I would recommend creating an validation / error handling class like the one mentioned at the link below:http://www.phpfreaks.com/tutorials/117/0.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.