'p' can only store "$", commas, dots or numbers.
How can I show an alert if it contains any other character?
if (p.match(/[^$,.\d]/))
alert('error!');
Live DEMO
You can use this Excellent regex cheat sheet.
Consider:
if (/[^$,\.\d]/.test(p)) {
// value has characters other than $ , . 0-9.
};
The regular expression test method returns a boolean value, whereas match returns an array and so is dependent on type conversion when used in a simlar manner.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With