Regular expression validation numbers

Source: Internet
Author: User
Tags regular expression

Integer: ^-?d+$
Non-negative floating-point number (positive floating-point number + 0): ^d+ (. d+)? $
Positive floating-point number ^ ([0-9]+.[ 0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*. [0-9]+) | ([0-9]*[1-9][0-9]*)] $
Non-positive floating-point number (negative floating-point number + 0) ^ ((-d+ (. d+)?) | (0+ (. 0+)?)) $
Negative floating-point number ^ (-([0-9]+.[ 0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*. [0-9]+) | ([0-9]*[1-9][0-9]*))] $
Floating-point number ^ (-?d+) (. d+)? $


Check for any number (real numbers)
function IsNumeric (strnumber) {
var newpar=/^ (-|+)? d+ (. d+)? $/
Alert (Newpar.test (Strnumber));}


Check for positive numbers
function Isunsignednumeric (strnumber) {
var newpar=/^d+ (. d+)? $/
Alert (Newpar.test (Strnumber)); }

Check whether it is an integer
function Isinteger (Strinteger) {
var newpar=/^ (-|+)? d+$/
Alert (Newpar.test (Strinteger)); }
Check if number
var txt = document.forms[0].num.value;
if (Txt.search ("^-?d+ (. d+)? $")!=0) {
Alert ("Please enter a number!");
Document.forms[0].num.select ();
return false;
}

Check if a positive integer
function Isunsignedinteger (Strinteger) {
var newpar=/^d+$/
Alert (Newpar.test (Strinteger));}
Check if integer
txt = document.forms[0].int.value;
if (Txt.search ("^-?d+$")!=0) {
Alert ("Please enter an integer!");
Document.forms[0].int.select ();
return false;
}


Check if number
function Isnum (s)
{
var pattern =/^d+ (. d+)? $/;
if (Pattern.test (s))
{
return true;
}
return false;
}
Check if integer
function Isint (s)
{
var pattern =/^-?d+$/;
if (S.search (pattern)!=0)
{
return false;
}
return true;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.