I have a basic html form that adds some data to the page using PHP. I want to make this form field a “Price” field. My html is:
<input class="bids" name="comment" id="comment" tabindex="4" />
How can I fix this field so that users can’t enter random letters, dollar signs, dashes, or other weird formats. I want the output to be whole dollars. Sorry I’m a complete programming moron. 🙂
Use javascript with regex to only allow digits for the client side. You should also do a server side check using php & regex to make sure the post data only contains digits.
Here is a javascript function that checks to make sure that a particular field input contains only numbers.
Take a look at this javascript regex guide to help you.
Don’t forget to do the PHP checking on the server side as well…
The PHP regex function would look something like: