Home PHP JavaScript CSS WordPress APIs .htaccess Other How-To Useful Scripts What I Recommend
Posted on by Aleksandar Gichevski ()
Often we need to put html form to collect data from visitors. It is quite easy and straightforward process to process the data if the information is entered correctly. But from my experience people not always enter the data in the correct format as we need it. In this article I will show you example on validation with JavaScript where visitor should enter only numbers. We are going to use regex to check the entered value in the form.

1. Accepting only numbers

This function will return "true" only if the value contains numbers without any other character.

Demo

2. Accepting numbers and dots

This function will return "true" if the value contains numbers only or numbers and dots. Also the value must start and end with a number.

Here you can change the dot(.) with comma(,) for other format.

Demo


Other Posts You Might Like

Get a fast, free website audit


Enter your URL below to get full in-depth SEO report and tips.

‚Äč

Useful Scripts

Most Popular Posts

Recent Posts

June 14th, 2014
Website Optimization Using Gzip Compression

June 10th, 2014
Google Search AutoComplete API

May 14th, 2014
What is a Tag Cloud and How to Calculate it by Formula

March 27th, 2014
Error writing file /tmp (errcode 28) Solved!

February 15th, 2014
Fixed CSS & HTML Navigation Bar

February 9th, 2014
Benchmark Your Server (CPU, File IO, MySQL) with SysBench

February 8th, 2014
JavaScript Array Basics

January 29th, 2014
JVZoo IPN API in PHP

January 25th, 2014
Payoneer Debit Card for Freelancers to receive money online

January 24th, 2014
How HTML Color Codes are generated?

Read Latest Posts directly on Facebook

Archive