C#: Min to max number of digits after a decimalHow to validate decimal number input to restrict them to only two decimal places?Validate decimal numbers in JavaScript - IsNumeric()What are the correct version numbers for C#?How do I generate a random int number?Regex to validate a number with only one digit following a decimalhow to limit only two digits after decimal point using Regex ValidatorRegular expression for a decimal with a max of 2 digits before decimal pointRegex on JavaScript to accept only numbers with 2 decimalsregex for decimal value restrict 16 digitHow to limit total number of digits in a decimal numberregular expression for number and decimal points in javascript
Temporarily disable WLAN internet access for children, but allow it for adults
What is Cash Advance APR?
Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?
Calculating total slots
Why would a new[] expression ever invoke a destructor?
Are Captain Marvel's powers affected by Thanos' actions in Infinity War
Open a doc from terminal, but not by its name
What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?
Unexpected behavior of the procedure `Area` on the object 'Polygon'
Mimic lecturing on blackboard, facing audience
What is going on with 'gets(stdin)' on the site coderbyte?
What if a revenant (monster) gains fire resistance?
Can a stoichiometric mixture of oxygen and methane exist as a liquid at standard pressure and some (low) temperature?
Can a Canadian Travel to the USA twice, less than 180 days each time?
Fear of getting stuck on one programming language / technology that is not used in my country
Creepy dinosaur pc game identification
Strong empirical falsification of quantum mechanics based on vacuum energy density
Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?
Why Shazam when there is already Superman?
What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?
Biological Blimps: Propulsion
Why should universal income be universal?
How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?
Picking the different solutions to the time independent Schrodinger eqaution
C#: Min to max number of digits after a decimal
How to validate decimal number input to restrict them to only two decimal places?Validate decimal numbers in JavaScript - IsNumeric()What are the correct version numbers for C#?How do I generate a random int number?Regex to validate a number with only one digit following a decimalhow to limit only two digits after decimal point using Regex ValidatorRegular expression for a decimal with a max of 2 digits before decimal pointRegex on JavaScript to accept only numbers with 2 decimalsregex for decimal value restrict 16 digitHow to limit total number of digits in a decimal numberregular expression for number and decimal points in javascript
I'm trying to do a check for a user input for the rate entered, I want to accept the value entered if it has min 2 digits to a max of 5 digits after the decimal.
Valid Example:
*1.12
*1.123
*1.1234
*1.12345
Not Valid:
1
1.1
1.123456
etc.
I've been trying to get it with Regex but right now it only allows only 5 digits after the decimal nothing less nothing more. Here's the code:
//Check if the string is a double
bool IsDouble(string s)
var regex = new Regex(@"^d+.d5?$");
var check = regex.IsMatch(s);
return check;
A little help would be greatly appreciated.
c# regex validation
add a comment |
I'm trying to do a check for a user input for the rate entered, I want to accept the value entered if it has min 2 digits to a max of 5 digits after the decimal.
Valid Example:
*1.12
*1.123
*1.1234
*1.12345
Not Valid:
1
1.1
1.123456
etc.
I've been trying to get it with Regex but right now it only allows only 5 digits after the decimal nothing less nothing more. Here's the code:
//Check if the string is a double
bool IsDouble(string s)
var regex = new Regex(@"^d+.d5?$");
var check = regex.IsMatch(s);
return check;
A little help would be greatly appreciated.
c# regex validation
add a comment |
I'm trying to do a check for a user input for the rate entered, I want to accept the value entered if it has min 2 digits to a max of 5 digits after the decimal.
Valid Example:
*1.12
*1.123
*1.1234
*1.12345
Not Valid:
1
1.1
1.123456
etc.
I've been trying to get it with Regex but right now it only allows only 5 digits after the decimal nothing less nothing more. Here's the code:
//Check if the string is a double
bool IsDouble(string s)
var regex = new Regex(@"^d+.d5?$");
var check = regex.IsMatch(s);
return check;
A little help would be greatly appreciated.
c# regex validation
I'm trying to do a check for a user input for the rate entered, I want to accept the value entered if it has min 2 digits to a max of 5 digits after the decimal.
Valid Example:
*1.12
*1.123
*1.1234
*1.12345
Not Valid:
1
1.1
1.123456
etc.
I've been trying to get it with Regex but right now it only allows only 5 digits after the decimal nothing less nothing more. Here's the code:
//Check if the string is a double
bool IsDouble(string s)
var regex = new Regex(@"^d+.d5?$");
var check = regex.IsMatch(s);
return check;
A little help would be greatly appreciated.
c# regex validation
c# regex validation
edited Jan 30 '14 at 14:54
crush
12.6k74590
12.6k74590
asked Jan 30 '14 at 14:25
kknaguibkknaguib
4061927
4061927
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
This should do it:
^d+.d2,5$
Great thanks man!
– kknaguib
Jan 30 '14 at 14:32
add a comment |
Use the pattern
"^d+.d2,5?$"
to match between 2 and 5 characters
Thanks! Works like a charm
– kknaguib
Jan 30 '14 at 14:36
add a comment |
Try this Regex
you can specify your own range here d2,5
^s*-?[1-9]d*(.d2,5)?s*$
(Or)
^(d1,5|d0,5.d2,5)$
REGEX DEMO
This will accept integers that are not allowed.
– Toto
Jan 30 '14 at 14:41
add a comment |
A non-regex solution
It also returns the decimal
public int? DecimalAfter (string strDec, out decimal? decNull)
int? decAfter = null;
strDec = strDec.Trim();
decimal dec;
if (decimal.TryParse(strDec, out dec))
decNull = dec;
int decPos = strDec.IndexOf('.');
if (decPos == -1)
decAfter = 0;
else
decAfter = strDec.Length - decPos - 1;
else decNull = null;
return decAfter;
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%2f21459104%2fc-min-to-max-number-of-digits-after-a-decimal%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
This should do it:
^d+.d2,5$
Great thanks man!
– kknaguib
Jan 30 '14 at 14:32
add a comment |
This should do it:
^d+.d2,5$
Great thanks man!
– kknaguib
Jan 30 '14 at 14:32
add a comment |
This should do it:
^d+.d2,5$
This should do it:
^d+.d2,5$
answered Jan 30 '14 at 14:29
Patrick QuirkPatrick Quirk
18k14373
18k14373
Great thanks man!
– kknaguib
Jan 30 '14 at 14:32
add a comment |
Great thanks man!
– kknaguib
Jan 30 '14 at 14:32
Great thanks man!
– kknaguib
Jan 30 '14 at 14:32
Great thanks man!
– kknaguib
Jan 30 '14 at 14:32
add a comment |
Use the pattern
"^d+.d2,5?$"
to match between 2 and 5 characters
Thanks! Works like a charm
– kknaguib
Jan 30 '14 at 14:36
add a comment |
Use the pattern
"^d+.d2,5?$"
to match between 2 and 5 characters
Thanks! Works like a charm
– kknaguib
Jan 30 '14 at 14:36
add a comment |
Use the pattern
"^d+.d2,5?$"
to match between 2 and 5 characters
Use the pattern
"^d+.d2,5?$"
to match between 2 and 5 characters
answered Jan 30 '14 at 14:29
D StanleyD Stanley
124k9116180
124k9116180
Thanks! Works like a charm
– kknaguib
Jan 30 '14 at 14:36
add a comment |
Thanks! Works like a charm
– kknaguib
Jan 30 '14 at 14:36
Thanks! Works like a charm
– kknaguib
Jan 30 '14 at 14:36
Thanks! Works like a charm
– kknaguib
Jan 30 '14 at 14:36
add a comment |
Try this Regex
you can specify your own range here d2,5
^s*-?[1-9]d*(.d2,5)?s*$
(Or)
^(d1,5|d0,5.d2,5)$
REGEX DEMO
This will accept integers that are not allowed.
– Toto
Jan 30 '14 at 14:41
add a comment |
Try this Regex
you can specify your own range here d2,5
^s*-?[1-9]d*(.d2,5)?s*$
(Or)
^(d1,5|d0,5.d2,5)$
REGEX DEMO
This will accept integers that are not allowed.
– Toto
Jan 30 '14 at 14:41
add a comment |
Try this Regex
you can specify your own range here d2,5
^s*-?[1-9]d*(.d2,5)?s*$
(Or)
^(d1,5|d0,5.d2,5)$
REGEX DEMO
Try this Regex
you can specify your own range here d2,5
^s*-?[1-9]d*(.d2,5)?s*$
(Or)
^(d1,5|d0,5.d2,5)$
REGEX DEMO
answered Jan 30 '14 at 14:31
Vignesh Kumar AVignesh Kumar A
18.7k104187
18.7k104187
This will accept integers that are not allowed.
– Toto
Jan 30 '14 at 14:41
add a comment |
This will accept integers that are not allowed.
– Toto
Jan 30 '14 at 14:41
This will accept integers that are not allowed.
– Toto
Jan 30 '14 at 14:41
This will accept integers that are not allowed.
– Toto
Jan 30 '14 at 14:41
add a comment |
A non-regex solution
It also returns the decimal
public int? DecimalAfter (string strDec, out decimal? decNull)
int? decAfter = null;
strDec = strDec.Trim();
decimal dec;
if (decimal.TryParse(strDec, out dec))
decNull = dec;
int decPos = strDec.IndexOf('.');
if (decPos == -1)
decAfter = 0;
else
decAfter = strDec.Length - decPos - 1;
else decNull = null;
return decAfter;
add a comment |
A non-regex solution
It also returns the decimal
public int? DecimalAfter (string strDec, out decimal? decNull)
int? decAfter = null;
strDec = strDec.Trim();
decimal dec;
if (decimal.TryParse(strDec, out dec))
decNull = dec;
int decPos = strDec.IndexOf('.');
if (decPos == -1)
decAfter = 0;
else
decAfter = strDec.Length - decPos - 1;
else decNull = null;
return decAfter;
add a comment |
A non-regex solution
It also returns the decimal
public int? DecimalAfter (string strDec, out decimal? decNull)
int? decAfter = null;
strDec = strDec.Trim();
decimal dec;
if (decimal.TryParse(strDec, out dec))
decNull = dec;
int decPos = strDec.IndexOf('.');
if (decPos == -1)
decAfter = 0;
else
decAfter = strDec.Length - decPos - 1;
else decNull = null;
return decAfter;
A non-regex solution
It also returns the decimal
public int? DecimalAfter (string strDec, out decimal? decNull)
int? decAfter = null;
strDec = strDec.Trim();
decimal dec;
if (decimal.TryParse(strDec, out dec))
decNull = dec;
int decPos = strDec.IndexOf('.');
if (decPos == -1)
decAfter = 0;
else
decAfter = strDec.Length - decPos - 1;
else decNull = null;
return decAfter;
answered Jan 30 '14 at 14:59
paparazzopaparazzo
37.7k1775140
37.7k1775140
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%2f21459104%2fc-min-to-max-number-of-digits-after-a-decimal%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