Regular Expression to Validate if it is not a Decimal or Integer NumberHow to validate an email address in JavaScript?A comprehensive regex for phone number validationWhat is the best regular expression to check if a string is a valid URL?Is there a regular expression to detect a valid regular expression?How to validate an email address using a regular expression?What are the correct version numbers for C#?Regular expression to match a line that doesn't contain a wordHow do you access the matched groups in a JavaScript regular expression?Regular Expressions: Is there an AND operator?How do you use a variable in a regular expression?
the meaning of 'carry' in a novel
Simple function that simulates survey results based on sample size and probability
Is the Starlink array really visible from Earth?
What are the real benefits of using Salesforce DX?
Crossing US border with music files I'm legally allowed to possess
how to grep in the output of ls -a
I unknowingly submitted plagarised work
Writing with dry erase marker on Shabbos, is it permitted?
Is CD audio quality good enough?
Were pens caps holes designed to prevent death by suffocation if swallowed?
Flying domestically in the US, is my State Issued ID all I need to get past security?
Is there an efficient way to replace text matching the entire content of one file with the entire content of another file?
Why are C64 games inconsistent with which joystick port they use?
What does the view outside my ship traveling at light speed look like?
Are these reasonable traits for someone with autism?
A steel cutting sword?
Have 1.5% of all nuclear reactors ever built melted down?
Why do they consider the Ori false gods?
Why does Mjolnir fall down in Age of Ultron but not in Endgame?
I think I may have violated academic integrity last year - what should I do?
How should I introduce map drawing to my players?
How to respond to an upset student?
At what point in European history could a government build a printing press given a basic description?
Count Even Digits In Number
Regular Expression to Validate if it is not a Decimal or Integer Number
How to validate an email address in JavaScript?A comprehensive regex for phone number validationWhat is the best regular expression to check if a string is a valid URL?Is there a regular expression to detect a valid regular expression?How to validate an email address using a regular expression?What are the correct version numbers for C#?Regular expression to match a line that doesn't contain a wordHow do you access the matched groups in a JavaScript regular expression?Regular Expressions: Is there an AND operator?How do you use a variable in a regular expression?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to find a regular expression to find out the number which is not entered as proper decimal or integer number in a input box
Examples
- 1.. - Catch // consecutive Repeating dots
- ABC - Catch // All Alphabets
- 1.1.1- Catch // dots repeating in a number
- !,@,#- Catch // All Special Characters
My current below allow me to catch all examples except example -3 where decimal dots can be repeated in any combination.
void T1_HTextChanged(object sender, EventArgs e)
[.]2"))
MessageBox.Show("Please enter only numbers.");
T1_H.Text="";
c# regex
add a comment |
I am trying to find a regular expression to find out the number which is not entered as proper decimal or integer number in a input box
Examples
- 1.. - Catch // consecutive Repeating dots
- ABC - Catch // All Alphabets
- 1.1.1- Catch // dots repeating in a number
- !,@,#- Catch // All Special Characters
My current below allow me to catch all examples except example -3 where decimal dots can be repeated in any combination.
void T1_HTextChanged(object sender, EventArgs e)
[.]2"))
MessageBox.Show("Please enter only numbers.");
T1_H.Text="";
c# regex
you could, instead, use try Convert.ToInt32(input);catch(Exception)// not int. If yiu really want to valid using regex, then try: -?[0-9]+(.[0.9]+)? to check is the input is a number.
– Vinícius Gabriel
Mar 24 at 6:07
P.S.: You can negate the regex to check if the input is not a number... obviously
– Vinícius Gabriel
Mar 24 at 6:09
Try this regex:^[0-9]+([.][0-9]1,2)?$
. Working example: regex101.com/r/iRaRPX/1. It will check for all integers and decimal numbers upto two decimal points. You can change that according to your req.
– Rahul Sharma
Mar 24 at 6:12
4
int.TryParse
anddecimal.TryParse
are better options than regex.
– Chetan Ranpariya
Mar 24 at 6:14
Also you can use NumericUpDown instead of TextBox.
– Alexander Petrov
Mar 24 at 9:33
add a comment |
I am trying to find a regular expression to find out the number which is not entered as proper decimal or integer number in a input box
Examples
- 1.. - Catch // consecutive Repeating dots
- ABC - Catch // All Alphabets
- 1.1.1- Catch // dots repeating in a number
- !,@,#- Catch // All Special Characters
My current below allow me to catch all examples except example -3 where decimal dots can be repeated in any combination.
void T1_HTextChanged(object sender, EventArgs e)
[.]2"))
MessageBox.Show("Please enter only numbers.");
T1_H.Text="";
c# regex
I am trying to find a regular expression to find out the number which is not entered as proper decimal or integer number in a input box
Examples
- 1.. - Catch // consecutive Repeating dots
- ABC - Catch // All Alphabets
- 1.1.1- Catch // dots repeating in a number
- !,@,#- Catch // All Special Characters
My current below allow me to catch all examples except example -3 where decimal dots can be repeated in any combination.
void T1_HTextChanged(object sender, EventArgs e)
[.]2"))
MessageBox.Show("Please enter only numbers.");
T1_H.Text="";
c# regex
c# regex
edited Mar 24 at 8:48
James Z
11.2k72037
11.2k72037
asked Mar 24 at 5:59
Srinath SriSrinath Sri
1
1
you could, instead, use try Convert.ToInt32(input);catch(Exception)// not int. If yiu really want to valid using regex, then try: -?[0-9]+(.[0.9]+)? to check is the input is a number.
– Vinícius Gabriel
Mar 24 at 6:07
P.S.: You can negate the regex to check if the input is not a number... obviously
– Vinícius Gabriel
Mar 24 at 6:09
Try this regex:^[0-9]+([.][0-9]1,2)?$
. Working example: regex101.com/r/iRaRPX/1. It will check for all integers and decimal numbers upto two decimal points. You can change that according to your req.
– Rahul Sharma
Mar 24 at 6:12
4
int.TryParse
anddecimal.TryParse
are better options than regex.
– Chetan Ranpariya
Mar 24 at 6:14
Also you can use NumericUpDown instead of TextBox.
– Alexander Petrov
Mar 24 at 9:33
add a comment |
you could, instead, use try Convert.ToInt32(input);catch(Exception)// not int. If yiu really want to valid using regex, then try: -?[0-9]+(.[0.9]+)? to check is the input is a number.
– Vinícius Gabriel
Mar 24 at 6:07
P.S.: You can negate the regex to check if the input is not a number... obviously
– Vinícius Gabriel
Mar 24 at 6:09
Try this regex:^[0-9]+([.][0-9]1,2)?$
. Working example: regex101.com/r/iRaRPX/1. It will check for all integers and decimal numbers upto two decimal points. You can change that according to your req.
– Rahul Sharma
Mar 24 at 6:12
4
int.TryParse
anddecimal.TryParse
are better options than regex.
– Chetan Ranpariya
Mar 24 at 6:14
Also you can use NumericUpDown instead of TextBox.
– Alexander Petrov
Mar 24 at 9:33
you could, instead, use try Convert.ToInt32(input);catch(Exception)// not int. If yiu really want to valid using regex, then try: -?[0-9]+(.[0.9]+)? to check is the input is a number.
– Vinícius Gabriel
Mar 24 at 6:07
you could, instead, use try Convert.ToInt32(input);catch(Exception)// not int. If yiu really want to valid using regex, then try: -?[0-9]+(.[0.9]+)? to check is the input is a number.
– Vinícius Gabriel
Mar 24 at 6:07
P.S.: You can negate the regex to check if the input is not a number... obviously
– Vinícius Gabriel
Mar 24 at 6:09
P.S.: You can negate the regex to check if the input is not a number... obviously
– Vinícius Gabriel
Mar 24 at 6:09
Try this regex:
^[0-9]+([.][0-9]1,2)?$
. Working example: regex101.com/r/iRaRPX/1. It will check for all integers and decimal numbers upto two decimal points. You can change that according to your req.– Rahul Sharma
Mar 24 at 6:12
Try this regex:
^[0-9]+([.][0-9]1,2)?$
. Working example: regex101.com/r/iRaRPX/1. It will check for all integers and decimal numbers upto two decimal points. You can change that according to your req.– Rahul Sharma
Mar 24 at 6:12
4
4
int.TryParse
and decimal.TryParse
are better options than regex.– Chetan Ranpariya
Mar 24 at 6:14
int.TryParse
and decimal.TryParse
are better options than regex.– Chetan Ranpariya
Mar 24 at 6:14
Also you can use NumericUpDown instead of TextBox.
– Alexander Petrov
Mar 24 at 9:33
Also you can use NumericUpDown instead of TextBox.
– Alexander Petrov
Mar 24 at 9:33
add a comment |
3 Answers
3
active
oldest
votes
If you really want to use a regexp you can use: ^[0-9]+(.[0-9]+)?$
.
You can test it here https://regex101.com/r/UB6eRT/1
If you want to know if it's a valid number you can also try to convert it and check if you get an error.
add a comment |
Try this regex:
^[0-9]+([.][0-9]1,2)?$
Explanation:
- ^ asserts position at start of a line
- Match a single character present in the list below [0-9]+
+ Quantifier — Matches between one and unlimited times, as many times as possible,
giving back as needed (greedy)
0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)- 1st Capturing Group ([.][0-9]1,2)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)- Match a single character present in the list below [.]
. matches the character . literally (case sensitive) - Match a single character present in the list below [0-9]1,2
1,2 Quantifier — Matches between 1 and 2 times, as many times as possible, giving back as needed (greedy) - 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
- $ asserts position at the end of a line
Working example: https://regex101.com/r/iRaRPX/1/
It will check for all integers and decimal numbers up to two decimal points. You can change that according to your requirement.
add a comment |
If you want to achieve this with Regular expression, you can use.
^(d*.)?d+$
Demo
But please be aware that you can use Decimal.TryParse
as well. You can read more on Decimal.TryParse here
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321134%2fregular-expression-to-validate-if-it-is-not-a-decimal-or-integer-number%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you really want to use a regexp you can use: ^[0-9]+(.[0-9]+)?$
.
You can test it here https://regex101.com/r/UB6eRT/1
If you want to know if it's a valid number you can also try to convert it and check if you get an error.
add a comment |
If you really want to use a regexp you can use: ^[0-9]+(.[0-9]+)?$
.
You can test it here https://regex101.com/r/UB6eRT/1
If you want to know if it's a valid number you can also try to convert it and check if you get an error.
add a comment |
If you really want to use a regexp you can use: ^[0-9]+(.[0-9]+)?$
.
You can test it here https://regex101.com/r/UB6eRT/1
If you want to know if it's a valid number you can also try to convert it and check if you get an error.
If you really want to use a regexp you can use: ^[0-9]+(.[0-9]+)?$
.
You can test it here https://regex101.com/r/UB6eRT/1
If you want to know if it's a valid number you can also try to convert it and check if you get an error.
edited Mar 24 at 6:18
answered Mar 24 at 6:12
François P.François P.
2,125716
2,125716
add a comment |
add a comment |
Try this regex:
^[0-9]+([.][0-9]1,2)?$
Explanation:
- ^ asserts position at start of a line
- Match a single character present in the list below [0-9]+
+ Quantifier — Matches between one and unlimited times, as many times as possible,
giving back as needed (greedy)
0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)- 1st Capturing Group ([.][0-9]1,2)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)- Match a single character present in the list below [.]
. matches the character . literally (case sensitive) - Match a single character present in the list below [0-9]1,2
1,2 Quantifier — Matches between 1 and 2 times, as many times as possible, giving back as needed (greedy) - 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
- $ asserts position at the end of a line
Working example: https://regex101.com/r/iRaRPX/1/
It will check for all integers and decimal numbers up to two decimal points. You can change that according to your requirement.
add a comment |
Try this regex:
^[0-9]+([.][0-9]1,2)?$
Explanation:
- ^ asserts position at start of a line
- Match a single character present in the list below [0-9]+
+ Quantifier — Matches between one and unlimited times, as many times as possible,
giving back as needed (greedy)
0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)- 1st Capturing Group ([.][0-9]1,2)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)- Match a single character present in the list below [.]
. matches the character . literally (case sensitive) - Match a single character present in the list below [0-9]1,2
1,2 Quantifier — Matches between 1 and 2 times, as many times as possible, giving back as needed (greedy) - 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
- $ asserts position at the end of a line
Working example: https://regex101.com/r/iRaRPX/1/
It will check for all integers and decimal numbers up to two decimal points. You can change that according to your requirement.
add a comment |
Try this regex:
^[0-9]+([.][0-9]1,2)?$
Explanation:
- ^ asserts position at start of a line
- Match a single character present in the list below [0-9]+
+ Quantifier — Matches between one and unlimited times, as many times as possible,
giving back as needed (greedy)
0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)- 1st Capturing Group ([.][0-9]1,2)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)- Match a single character present in the list below [.]
. matches the character . literally (case sensitive) - Match a single character present in the list below [0-9]1,2
1,2 Quantifier — Matches between 1 and 2 times, as many times as possible, giving back as needed (greedy) - 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
- $ asserts position at the end of a line
Working example: https://regex101.com/r/iRaRPX/1/
It will check for all integers and decimal numbers up to two decimal points. You can change that according to your requirement.
Try this regex:
^[0-9]+([.][0-9]1,2)?$
Explanation:
- ^ asserts position at start of a line
- Match a single character present in the list below [0-9]+
+ Quantifier — Matches between one and unlimited times, as many times as possible,
giving back as needed (greedy)
0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)- 1st Capturing Group ([.][0-9]1,2)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)- Match a single character present in the list below [.]
. matches the character . literally (case sensitive) - Match a single character present in the list below [0-9]1,2
1,2 Quantifier — Matches between 1 and 2 times, as many times as possible, giving back as needed (greedy) - 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
- $ asserts position at the end of a line
Working example: https://regex101.com/r/iRaRPX/1/
It will check for all integers and decimal numbers up to two decimal points. You can change that according to your requirement.
edited Mar 24 at 6:57
answered Mar 24 at 6:18
Rahul SharmaRahul Sharma
8301617
8301617
add a comment |
add a comment |
If you want to achieve this with Regular expression, you can use.
^(d*.)?d+$
Demo
But please be aware that you can use Decimal.TryParse
as well. You can read more on Decimal.TryParse here
add a comment |
If you want to achieve this with Regular expression, you can use.
^(d*.)?d+$
Demo
But please be aware that you can use Decimal.TryParse
as well. You can read more on Decimal.TryParse here
add a comment |
If you want to achieve this with Regular expression, you can use.
^(d*.)?d+$
Demo
But please be aware that you can use Decimal.TryParse
as well. You can read more on Decimal.TryParse here
If you want to achieve this with Regular expression, you can use.
^(d*.)?d+$
Demo
But please be aware that you can use Decimal.TryParse
as well. You can read more on Decimal.TryParse here
answered Mar 24 at 7:34
Anu ViswanAnu Viswan
6,2272526
6,2272526
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321134%2fregular-expression-to-validate-if-it-is-not-a-decimal-or-integer-number%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
you could, instead, use try Convert.ToInt32(input);catch(Exception)// not int. If yiu really want to valid using regex, then try: -?[0-9]+(.[0.9]+)? to check is the input is a number.
– Vinícius Gabriel
Mar 24 at 6:07
P.S.: You can negate the regex to check if the input is not a number... obviously
– Vinícius Gabriel
Mar 24 at 6:09
Try this regex:
^[0-9]+([.][0-9]1,2)?$
. Working example: regex101.com/r/iRaRPX/1. It will check for all integers and decimal numbers upto two decimal points. You can change that according to your req.– Rahul Sharma
Mar 24 at 6:12
4
int.TryParse
anddecimal.TryParse
are better options than regex.– Chetan Ranpariya
Mar 24 at 6:14
Also you can use NumericUpDown instead of TextBox.
– Alexander Petrov
Mar 24 at 9:33