Skip to content

Instantly share code, notes, and snippets.

@Kyly
Created November 8, 2018 19:50
Show Gist options
  • Select an option

  • Save Kyly/ecaa9f0e5ce0bc6e314b1e474c6c44db to your computer and use it in GitHub Desktop.

Select an option

Save Kyly/ecaa9f0e5ce0bc6e314b1e474c6c44db to your computer and use it in GitHub Desktop.
function validateNumber(value) {
let error;
if (!/^('^\\d+$')$/i.test(value)) {
error = 'Only numbers allowed';
}
return error;
}
Copy link

ghost commented Nov 8, 2018

1.1 = false
'1.1' = false
'1a1' = false
1.1 = false
11 = true

Copy link

ghost commented Nov 8, 2018

/^[0-9]*$/ checks if input only consists of the numbers 0-9 appearing 0 or more times

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment