Skip to content
Strip any extranous price characters such as `$` and make sure there is still a valid number
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.gitignore
README.md
index.js
makefile
package.json

README.md

Validate Number

Strip any extranous price characters such as $ and make sure there is still a valid number

Installation

npm install -S validate-number

Usage

When using with a valid number, you will get the number back without any extra characters

var validateNumber = require('validateNumber')
var extract = '-$1.99'
var price = validateNumber(extract)
console.log('price %s', price)

When using with a invalid number, you will get back null

var validateNumber = require('validateNumber')
var extract = '-$foobar'
var price = validateNumber(extract) // price will be null
console.log('price %s', price)
Something went wrong with that request. Please try again.