Linked Questions
20 questions linked to/from Regex to check whether a string contains only numbers
541
votes
17
answers
641k
views
Check if string contains only digits
I want to check if a string contains only digits. I used this:
var isANumber = isNaN(theValue) === false;
if (isANumber){
...
}
But, realized that it also allows + and -. Basically, I want to ...
2
votes
0
answers
636
views
Regex for "is every character in string numeric?" [duplicate]
I'm wondering what regex pattern I could use to detect if every character in a string is numeric.
So, here's what I'm thinking that isn't working:
stringr::str_detect("311apple", "[0-9]")
#> [1] ...
-4
votes
1
answer
347
views
Javascript regex to replace only numbers [duplicate]
I want a Javascript regex to replace only numbers i.e. all others alphabets and special characters are allowed.
-4
votes
1
answer
151
views
Javascript regex for accepting only number without "," or "." character [duplicate]
I'm looking for a regex javascript expression for allowing only numbers at this format 1234. Not 1,234 or 1.234. I'm having this regex now but it does not seem to work properly /[a-z]/i
0
votes
3
answers
272
views
Recognizing numbers from strings in node.js [duplicate]
How could I do it in Node.js to recognize if a string is a valid number?
Here are some examples of what I want:
"22" => true
"- 22" => true
"-22.23" => true
"22a" => false
"2a2" ...
0
votes
0
answers
90
views
Regex in ballerina is not working properly. how to fix it? [duplicate]
I have a function to check integer format using ballerina regex. I'm using ballerina 0.990.2 and it gives result=false. How can I check integer format using regex in ballerina lang?
function ...
1018
votes
12
answers
822k
views
Strip all non-numeric characters from string in JavaScript
Consider a non-DOM scenario where you'd want to remove all non-numeric characters from a string using JavaScript/ECMAScript. Any characters that are in range 0 - 9 should be kept.
var myString = '...
219
votes
22
answers
442k
views
Regular expression for floating point numbers
I have a task to match floating point numbers. I have written the following regular expression for it:
[-+]?[0-9]*\.?[0-9]*
But, it returns an error:
Invalid escape sequence (valid ones are \b \t ...
5
votes
6
answers
42k
views
JavaScript Regular Expression Validation
I'm attempting to validate a field name to match a certain format in JavaScript using Regular Expressions.
I need the string inputted to resemble this:
word\word\word
So anything inputted can't be ...
2
votes
3
answers
5k
views
Check if String can be converted to number
I created the following Typescript extension to convert a string to Number:
declare global {
interface String {
toNumber(): number | null;
}
}
String.prototype.toNumber = function(this: ...
2
votes
1
answer
4k
views
Ui-router route parameter with regex
I feel like this is simple but I can't get it to work...
I am using Ui-Router 2.11 which includes optional parameters with regex expressions.
I have this url which works
'/event/{eventId:[0-9]}'
...
0
votes
1
answer
7k
views
how to check input .indexOf for multiple characters?
I am trying to check if the user enters at least one number. If yes, the output = 'okey' else 'no number'. This works only for the first number, however when I enter 2, the function answers 'no number'...
0
votes
3
answers
3k
views
React controlled number input jumps when deleting decimal point
I have a controlled number input in a React app, and when I remove all the digits right of the decimal point, the decimal point itself is removed. So when I have 1.1, and remove the rightmost 1, it ...
1
vote
4
answers
1k
views
Show popover on text box if value is exceeded
I am new in javascript. I have no idea of javascript and I am still learning. I want a small help.
I have a label with a number. The user has to manually enter a number in a textbox. If the value ...
0
votes
2
answers
749
views
synchronize jtextfield value into only integer value using document listener
Following the Question Synchronize JTextField values by property change listener
I have tried to modify the example from the answer using document listener. What I wanted to modify was to synchronize ...