This question already has answers here:
Strip all non-numeric characters from string in JavaScript
(12 answers)
Closed 8 years ago.
I am trying to replace with a blank all characters except numbers, but this doesn't works:
s.replace(/(?!\d)/g, '')
Thanks!
Use negative character classes:
s.replace(/[^0-9]+/g, '')
or s.replace(/[^\d]+/g, '')
or s.replace(/\D+/g, '')
Related
This question already has answers here:
How can I use backslashes (\) in a string?
(4 answers)
Why do regex constructors need to be double escaped?
(5 answers)
Closed 2 years ago.
I can't seem to find the issue with this code:
const regex = "/tel:\+61(\d+)/g";
const subscriberNumber = senderAddress.match(regex);
For input text, senderAddress = tel:+619123456789 the subscriberNumber is null.
What's causing it to return null?
You haven't escaped the + in 61. + is used as a concatenation operator too.
I don’t think the parentheses around \d+ are necessary.
This question already has answers here:
numbers not allowed (0-9) - Regex Expression in javascript
(6 answers)
Closed 2 years ago.
I am trying to create a react(javascript) form, In that one field should allow all values (Uppercase letters, Lowercase letters and special characters) but not numbers.
Is there any regex or any other solution?
Thanks in advance.
You can simply check that a string DOESN'T contain numbers using regex \d which matches all numbers:
!(/\d/.test(string))
This question already has answers here:
Regex to check whether a string contains only numbers [duplicate]
(21 answers)
Closed 4 years ago.
I want a Javascript regex to replace only numbers i.e. all others alphabets and special characters are allowed.
This should do:
let string= "26kgsl5"
let newString = string.replace(/[0-9]/g, "");
console.log(newString);
This question already has answers here:
Regex to validate password strength
(11 answers)
Closed 4 years ago.
What can be a valid regex for a password that contains at least 8 characters in which there should be one upper-case,one lower-case and one number?
Here is a regular expression for a string with at least 8 characters, one upper-case, one lower-case and one number.
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$
This question already has answers here:
How to convert a currency string to a double with Javascript?
(23 answers)
Closed 6 years ago.
I have a string like this
"$2,099,585.43"
"$" maybe any symbol, like #,#..etc.
I want to convert this into 2099585.43
Is there any simple way to do this?
Use String#replace and remove characters which are not a digit or dot.
console.log(
"$2,099,585.43".replace(/[^\d.]/g, '')
)