Number ValidationThis script allows you to check that a field contains a numeric whole number value. Choose whether to only allow positive numbers or positive numbers plus zero.Script CodeGrab a copy of the file below and place it in the same directory as the Web page on which you will use the script (if you wish to place the script file in a different directory you will need to make the necessary adjustments to the src attribute of the script tag that calls it).The code below should be placed between the <body> and </body> tags where you want the phone number field to appear. ExampleA working sample of the script is shown below.OptionsYou can change the appearance of the input box and the button by adding the phone_number id and sub_ph id to your style sheet and editing as desired.Be sure to set the url of the form's action attribute in the HTML code to reflect your form handling script on your server: <form action="form_script_url" onsubmit="return check_the_number();"> You can choose how the viewer should format the number by editing the num_division variable in the javascript code (instructions in code comments):
/* Set whether to allow postive, negative or zero. AccessibilityA backup to the script via a server-side script that validates the number should suffice (and is highly recommended for security reasons to avoid bad data being passed). |