Regular expression for length limit 10 digit before decimal till 2 decimal place with Number only?
i want a regular expression for length limit 10 digit with 2 decimal place numbers with only numbers allowed.10 digit before decimal
allowed
1
1111111111
111
1111111111.22
.2
1.2
1.22
Not allowed
4.
.
-1
abc
Null
Emptystring
""
1.222
-1.22
111111111111
tried but not working
^[0-9]*(.[0-9]0,2)?$
javascript regex
|
show 2 more comments
i want a regular expression for length limit 10 digit with 2 decimal place numbers with only numbers allowed.10 digit before decimal
allowed
1
1111111111
111
1111111111.22
.2
1.2
1.22
Not allowed
4.
.
-1
abc
Null
Emptystring
""
1.222
-1.22
111111111111
tried but not working
^[0-9]*(.[0-9]0,2)?$
javascript regex
How did you devise this regex? Your regex doesn't match the-
character for sign.
– Dai
Nov 13 '18 at 5:34
@CertainPerformance fixed
– user9461718
Nov 13 '18 at 5:39
Do you want to match1.2
? or1.22
– vks
Nov 13 '18 at 7:05
@vks both needed
– user9461718
Nov 14 '18 at 6:16
1
@DeepakJain the answer u accepted accepts.
as well.1.
as well
– vks
Nov 14 '18 at 6:25
|
show 2 more comments
i want a regular expression for length limit 10 digit with 2 decimal place numbers with only numbers allowed.10 digit before decimal
allowed
1
1111111111
111
1111111111.22
.2
1.2
1.22
Not allowed
4.
.
-1
abc
Null
Emptystring
""
1.222
-1.22
111111111111
tried but not working
^[0-9]*(.[0-9]0,2)?$
javascript regex
i want a regular expression for length limit 10 digit with 2 decimal place numbers with only numbers allowed.10 digit before decimal
allowed
1
1111111111
111
1111111111.22
.2
1.2
1.22
Not allowed
4.
.
-1
abc
Null
Emptystring
""
1.222
-1.22
111111111111
tried but not working
^[0-9]*(.[0-9]0,2)?$
javascript regex
javascript regex
edited Nov 14 '18 at 7:11
asked Nov 13 '18 at 5:33
user9461718
How did you devise this regex? Your regex doesn't match the-
character for sign.
– Dai
Nov 13 '18 at 5:34
@CertainPerformance fixed
– user9461718
Nov 13 '18 at 5:39
Do you want to match1.2
? or1.22
– vks
Nov 13 '18 at 7:05
@vks both needed
– user9461718
Nov 14 '18 at 6:16
1
@DeepakJain the answer u accepted accepts.
as well.1.
as well
– vks
Nov 14 '18 at 6:25
|
show 2 more comments
How did you devise this regex? Your regex doesn't match the-
character for sign.
– Dai
Nov 13 '18 at 5:34
@CertainPerformance fixed
– user9461718
Nov 13 '18 at 5:39
Do you want to match1.2
? or1.22
– vks
Nov 13 '18 at 7:05
@vks both needed
– user9461718
Nov 14 '18 at 6:16
1
@DeepakJain the answer u accepted accepts.
as well.1.
as well
– vks
Nov 14 '18 at 6:25
How did you devise this regex? Your regex doesn't match the
-
character for sign.– Dai
Nov 13 '18 at 5:34
How did you devise this regex? Your regex doesn't match the
-
character for sign.– Dai
Nov 13 '18 at 5:34
@CertainPerformance fixed
– user9461718
Nov 13 '18 at 5:39
@CertainPerformance fixed
– user9461718
Nov 13 '18 at 5:39
Do you want to match
1.2
? or 1.22
– vks
Nov 13 '18 at 7:05
Do you want to match
1.2
? or 1.22
– vks
Nov 13 '18 at 7:05
@vks both needed
– user9461718
Nov 14 '18 at 6:16
@vks both needed
– user9461718
Nov 14 '18 at 6:16
1
1
@DeepakJain the answer u accepted accepts
.
as well.1.
as well– vks
Nov 14 '18 at 6:25
@DeepakJain the answer u accepted accepts
.
as well.1.
as well– vks
Nov 14 '18 at 6:25
|
show 2 more comments
2 Answers
2
active
oldest
votes
You're almost there - all you have to do is include a check that the string is not empty (which can be accomplished with a positive lookahead for .1,10
right after the ^
), and check that its first digit string has at most 10 characters (just use a 0,10
quantifier for the digits). Also note that [0-9]
simplifies to d
.
In order to also exclude trailing dots, repeat the digit after the dot with 1,2
instead of 0,2
:
^(?!$)d0,10(?:.d1,2)?$
https://regex101.com/r/Ah8dNu/5
11111111111 (11 digit are invalid) not working (only 10 digit allowed)
– user9461718
Nov 13 '18 at 5:42
10 digit before Decimal
– user9461718
Nov 13 '18 at 5:44
This matches.
which should not be valid value.regex101.com/r/Ah8dNu/3
– vks
Nov 13 '18 at 7:50
@vks I did notice that, OP had0,2
in his original code rather than1, 2
, seemed strange but I thought it was intentional
– CertainPerformance
Nov 13 '18 at 8:20
1
@DeepakJain use^(?!$)d0,10(?:.d1,2)?$
. See demo. regex101.com/r/Ah8dNu/4
– vks
Nov 14 '18 at 6:28
|
show 3 more comments
I have also prepared below RegEx.
Seems this will also work.
^[0-9]1,10((.)[0-9]0,2)0,1$
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%2f53274438%2fregular-expression-for-length-limit-10-digit-before-decimal-till-2-decimal-place%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You're almost there - all you have to do is include a check that the string is not empty (which can be accomplished with a positive lookahead for .1,10
right after the ^
), and check that its first digit string has at most 10 characters (just use a 0,10
quantifier for the digits). Also note that [0-9]
simplifies to d
.
In order to also exclude trailing dots, repeat the digit after the dot with 1,2
instead of 0,2
:
^(?!$)d0,10(?:.d1,2)?$
https://regex101.com/r/Ah8dNu/5
11111111111 (11 digit are invalid) not working (only 10 digit allowed)
– user9461718
Nov 13 '18 at 5:42
10 digit before Decimal
– user9461718
Nov 13 '18 at 5:44
This matches.
which should not be valid value.regex101.com/r/Ah8dNu/3
– vks
Nov 13 '18 at 7:50
@vks I did notice that, OP had0,2
in his original code rather than1, 2
, seemed strange but I thought it was intentional
– CertainPerformance
Nov 13 '18 at 8:20
1
@DeepakJain use^(?!$)d0,10(?:.d1,2)?$
. See demo. regex101.com/r/Ah8dNu/4
– vks
Nov 14 '18 at 6:28
|
show 3 more comments
You're almost there - all you have to do is include a check that the string is not empty (which can be accomplished with a positive lookahead for .1,10
right after the ^
), and check that its first digit string has at most 10 characters (just use a 0,10
quantifier for the digits). Also note that [0-9]
simplifies to d
.
In order to also exclude trailing dots, repeat the digit after the dot with 1,2
instead of 0,2
:
^(?!$)d0,10(?:.d1,2)?$
https://regex101.com/r/Ah8dNu/5
11111111111 (11 digit are invalid) not working (only 10 digit allowed)
– user9461718
Nov 13 '18 at 5:42
10 digit before Decimal
– user9461718
Nov 13 '18 at 5:44
This matches.
which should not be valid value.regex101.com/r/Ah8dNu/3
– vks
Nov 13 '18 at 7:50
@vks I did notice that, OP had0,2
in his original code rather than1, 2
, seemed strange but I thought it was intentional
– CertainPerformance
Nov 13 '18 at 8:20
1
@DeepakJain use^(?!$)d0,10(?:.d1,2)?$
. See demo. regex101.com/r/Ah8dNu/4
– vks
Nov 14 '18 at 6:28
|
show 3 more comments
You're almost there - all you have to do is include a check that the string is not empty (which can be accomplished with a positive lookahead for .1,10
right after the ^
), and check that its first digit string has at most 10 characters (just use a 0,10
quantifier for the digits). Also note that [0-9]
simplifies to d
.
In order to also exclude trailing dots, repeat the digit after the dot with 1,2
instead of 0,2
:
^(?!$)d0,10(?:.d1,2)?$
https://regex101.com/r/Ah8dNu/5
You're almost there - all you have to do is include a check that the string is not empty (which can be accomplished with a positive lookahead for .1,10
right after the ^
), and check that its first digit string has at most 10 characters (just use a 0,10
quantifier for the digits). Also note that [0-9]
simplifies to d
.
In order to also exclude trailing dots, repeat the digit after the dot with 1,2
instead of 0,2
:
^(?!$)d0,10(?:.d1,2)?$
https://regex101.com/r/Ah8dNu/5
edited Nov 14 '18 at 7:07
answered Nov 13 '18 at 5:40
CertainPerformanceCertainPerformance
90.5k165178
90.5k165178
11111111111 (11 digit are invalid) not working (only 10 digit allowed)
– user9461718
Nov 13 '18 at 5:42
10 digit before Decimal
– user9461718
Nov 13 '18 at 5:44
This matches.
which should not be valid value.regex101.com/r/Ah8dNu/3
– vks
Nov 13 '18 at 7:50
@vks I did notice that, OP had0,2
in his original code rather than1, 2
, seemed strange but I thought it was intentional
– CertainPerformance
Nov 13 '18 at 8:20
1
@DeepakJain use^(?!$)d0,10(?:.d1,2)?$
. See demo. regex101.com/r/Ah8dNu/4
– vks
Nov 14 '18 at 6:28
|
show 3 more comments
11111111111 (11 digit are invalid) not working (only 10 digit allowed)
– user9461718
Nov 13 '18 at 5:42
10 digit before Decimal
– user9461718
Nov 13 '18 at 5:44
This matches.
which should not be valid value.regex101.com/r/Ah8dNu/3
– vks
Nov 13 '18 at 7:50
@vks I did notice that, OP had0,2
in his original code rather than1, 2
, seemed strange but I thought it was intentional
– CertainPerformance
Nov 13 '18 at 8:20
1
@DeepakJain use^(?!$)d0,10(?:.d1,2)?$
. See demo. regex101.com/r/Ah8dNu/4
– vks
Nov 14 '18 at 6:28
11111111111 (11 digit are invalid) not working (only 10 digit allowed)
– user9461718
Nov 13 '18 at 5:42
11111111111 (11 digit are invalid) not working (only 10 digit allowed)
– user9461718
Nov 13 '18 at 5:42
10 digit before Decimal
– user9461718
Nov 13 '18 at 5:44
10 digit before Decimal
– user9461718
Nov 13 '18 at 5:44
This matches
.
which should not be valid value.regex101.com/r/Ah8dNu/3– vks
Nov 13 '18 at 7:50
This matches
.
which should not be valid value.regex101.com/r/Ah8dNu/3– vks
Nov 13 '18 at 7:50
@vks I did notice that, OP had
0,2
in his original code rather than 1, 2
, seemed strange but I thought it was intentional– CertainPerformance
Nov 13 '18 at 8:20
@vks I did notice that, OP had
0,2
in his original code rather than 1, 2
, seemed strange but I thought it was intentional– CertainPerformance
Nov 13 '18 at 8:20
1
1
@DeepakJain use
^(?!$)d0,10(?:.d1,2)?$
. See demo. regex101.com/r/Ah8dNu/4– vks
Nov 14 '18 at 6:28
@DeepakJain use
^(?!$)d0,10(?:.d1,2)?$
. See demo. regex101.com/r/Ah8dNu/4– vks
Nov 14 '18 at 6:28
|
show 3 more comments
I have also prepared below RegEx.
Seems this will also work.
^[0-9]1,10((.)[0-9]0,2)0,1$
add a comment |
I have also prepared below RegEx.
Seems this will also work.
^[0-9]1,10((.)[0-9]0,2)0,1$
add a comment |
I have also prepared below RegEx.
Seems this will also work.
^[0-9]1,10((.)[0-9]0,2)0,1$
I have also prepared below RegEx.
Seems this will also work.
^[0-9]1,10((.)[0-9]0,2)0,1$
answered Nov 13 '18 at 7:01
Ashish SapkaleAshish Sapkale
455212
455212
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%2f53274438%2fregular-expression-for-length-limit-10-digit-before-decimal-till-2-decimal-place%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
How did you devise this regex? Your regex doesn't match the
-
character for sign.– Dai
Nov 13 '18 at 5:34
@CertainPerformance fixed
– user9461718
Nov 13 '18 at 5:39
Do you want to match
1.2
? or1.22
– vks
Nov 13 '18 at 7:05
@vks both needed
– user9461718
Nov 14 '18 at 6:16
1
@DeepakJain the answer u accepted accepts
.
as well.1.
as well– vks
Nov 14 '18 at 6:25