I have a form for user to submit information. I need to makesure user entering numeric value for numeric field but not character string and viceversa I need to makesure user not entering numeric value for field that require character string value. I do it after user click on ’submit’.
Let’s say the field is called zipcode.
if ( isset($_POST['zipcode']) && is_numeric($_POST['zipcode'])
&& is_int($_POST['zipcode'] + 0)
)
To check if the input is numeric, We use is_numeric() function, and if it is numeric we cast it as a number by adding zero (or multiplying by 1) and check to see whether the number is an integer or a float.
1 Comment Already
Pingback & Trackback
Related Post
Leave Your Comments Below