x Did you like it? Well, then please consider making a donation :)

Validate numbers

If Possible, Don't Use Regex To Validate Numbers. If at all possible, use your language. There may be functions to help you determine if the value contained by a string is a valid number. That being said, if you're accepting a variety of formats (commas, etc.) you may not have a choice.

Tags: #digits, #numbers, #parsing, #real number, #validate, #validating. Views: 4062. stackoverflow, 7/12/2015
Link 1: http://www.systemtextregularexpressions.com/m13/validate-numbers
Link 2: http://www.systemtextregularexpressions.com/m13 (short)

Length: 0b, Line: 1, Cursor: 0

RegexOptions

IsMatch=true


#ValueIndexLengthGroupsCaptures
0001Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
10,10274Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
21,60324Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
31371Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
42391Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
59411Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
690432Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
70,0623Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
81,0863Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
91,00904Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
1010952Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
1110,0984Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
1210,001035Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
13201352Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
1420,51384Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
150,51433Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
1640,001475Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
1799,991535Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
Count: 18, Time: 00:00:00

Share (without adding to database):

Source code

0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
//.NET Regex.Match Online Tester: www.systemtextregularexpressions.com

//Namespace
using System.Text.RegularExpressions;

//Regex Pattern
string pattern = @"^([0]|\d{1,2})(?:,\d{1,2})?$";

//Regex example #1
Regex r = new Regex(@"^([0]|\d{1,2})(?:,\d{1,2})?$", RegexOptions.Multiline);
Match m1 = r.Match("input text");
MatchCollection mc1 = r.Matches("input text");

//Regex example #2
Match m2 = Regex.Match("input text", @"^([0]|\d{1,2})(?:,\d{1,2})?$", RegexOptions.Multiline);
MatchCollection mc2 = Regex.Matches("input text", @"^([0]|\d{1,2})(?:,\d{1,2})?$", RegexOptions.Multiline);
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
'.NET Regex.Match Online Tester: www.systemtextregularexpressions.com

'Namespace
Imports System.Text.RegularExpressions

'Regex Pattern
Dim pattern As String = "^([0]|\d{1,2})(?:,\d{1,2})?$"

'Regex example #1
Dim r As Regex = New Regex("^([0]|\d{1,2})(?:,\d{1,2})?$", RegexOptions.Multiline)
Dim m1 As Match = r.Match("input text")
Dim mc As MatchCollection = r.Matches("input text")

'Regex example #2
Dim m2 As Match = Regex.Match("input text", "^([0]|\d{1,2})(?:,\d{1,2})?$", RegexOptions.Multiline)
Dim mc2 As MatchCollection = Regex.Matches("input text", "^([0]|\d{1,2})(?:,\d{1,2})?$", RegexOptions.Multiline)

Home     Match     Replace     Split     Help     Library     Contacts     netregex rss

Made by Koshevoy Dmitry [8Bytes],

© 2014-2024 Ukraine, Nikolaev.