Is String an integer or float by regex - Node.js Regular expression

Node.js examples for Regular expression:Match

Description

Is String an integer or float by regex

Demo Code

String.prototype.isInteger = function()
{
return /^[\+\-]?(?:0x[0-9a-f]+|0[0-7]+|[0-9]+)$/i.test(this);
}

String.prototype.isFloat = function()
{
return /^[\+\-]?(\d+|\d*(?:\.\d+){1})(?:[eE][\+\-]?\d+)?$/.test(this);
}

String.prototype.isNumber = function()
{
return this.isInteger() || this.isFloat();
}

Related Tutorials