How to filter out certain combinations?How to validate an email address in JavaScript?How do I enumerate an enum in C#?What is the best way to filter a Java Collection?How to validate an email address using a regular expression?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow do I generate a random int number?list comprehension vs. lambda + filterText Box(Asp.net) value with 3 decimal places handle by Javascript - Regex
Is it OK to leave real names & info visible in business card portfolio?
Some interesting calculation puzzle that I made
Fivenum and a little bit
What to do with a rabbit in a survival situation?
How to deal with moral/legal subjects in writing?
When an electron changes its spin, or any other intrinsic property, is it still the same electron?
Single word for "refusing to move to next activity unless present one is completed."
How to drill holes in 3/8" thick steel plates?
Why return a static pointer instead of an out parameter?
Power/Loss diagram
Are there any medieval light sources without fire?
Integer Lists of Noah
Employers keep telling me my college isn't good enough - is there any way to fix this?
Is there any reason why MCU changed the Snap to Blip
Is there a strong legal guarantee that the U.S. can give to another country that it won't attack them?
Why did Harry Potter get a bedroom?
Has anyone in space seen or photographed a simple laser pointer from Earth?
How do you move up one folder in Finder?
For a hashing function like MD5, how similar can two plaintext strings be and still generate the same hash?
Is English unusual in having no second person plural form?
What is this little owl-like bird?
Can you cast a blanket Invisibility and let the targets see each other?
Graduate student with abysmal English writing skills, how to help
Do I have a right to cancel a purchase of foreign currency in the UK?
How to filter out certain combinations?
How to validate an email address in JavaScript?How do I enumerate an enum in C#?What is the best way to filter a Java Collection?How to validate an email address using a regular expression?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow do I generate a random int number?list comprehension vs. lambda + filterText Box(Asp.net) value with 3 decimal places handle by Javascript - Regex
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to filter the input of a TextBox using Regex. I need up to 3 numbers before the decimal point and I need 2 after it. This can be in any form.
I've tried changing the regex commands around but it creates errors and single inputs won't be valid. I'm using a TextBox in WPF to collect the data.
bool containsLetter = Regex.IsMatch(units.Text, "^[0-9]1,3([.] [0-9] 1,3)?$");
if (containsLetter == true)
MessageBox.Show("error");
return containsLetter;
I want the regex filter to accept these types of inputs:
111.11,
11.11,
1.11,
1.01,
100,
10,
1,
c# regex wpf filter
add a comment |
I'm trying to filter the input of a TextBox using Regex. I need up to 3 numbers before the decimal point and I need 2 after it. This can be in any form.
I've tried changing the regex commands around but it creates errors and single inputs won't be valid. I'm using a TextBox in WPF to collect the data.
bool containsLetter = Regex.IsMatch(units.Text, "^[0-9]1,3([.] [0-9] 1,3)?$");
if (containsLetter == true)
MessageBox.Show("error");
return containsLetter;
I want the regex filter to accept these types of inputs:
111.11,
11.11,
1.11,
1.01,
100,
10,
1,
c# regex wpf filter
4
Looks like all you have to do is remove the spaces from your regex pattern. Why did you add them in the first place?
– Ahmed Abdelhameed
Mar 26 at 1:46
if we have answered your question, could you please accept an answer/upvote as detailed in: stackoverflow.com/help/someone-answers
– Allan
Apr 2 at 0:53
add a comment |
I'm trying to filter the input of a TextBox using Regex. I need up to 3 numbers before the decimal point and I need 2 after it. This can be in any form.
I've tried changing the regex commands around but it creates errors and single inputs won't be valid. I'm using a TextBox in WPF to collect the data.
bool containsLetter = Regex.IsMatch(units.Text, "^[0-9]1,3([.] [0-9] 1,3)?$");
if (containsLetter == true)
MessageBox.Show("error");
return containsLetter;
I want the regex filter to accept these types of inputs:
111.11,
11.11,
1.11,
1.01,
100,
10,
1,
c# regex wpf filter
I'm trying to filter the input of a TextBox using Regex. I need up to 3 numbers before the decimal point and I need 2 after it. This can be in any form.
I've tried changing the regex commands around but it creates errors and single inputs won't be valid. I'm using a TextBox in WPF to collect the data.
bool containsLetter = Regex.IsMatch(units.Text, "^[0-9]1,3([.] [0-9] 1,3)?$");
if (containsLetter == true)
MessageBox.Show("error");
return containsLetter;
I want the regex filter to accept these types of inputs:
111.11,
11.11,
1.11,
1.01,
100,
10,
1,
c# regex wpf filter
c# regex wpf filter
edited Mar 26 at 1:49
Ahmed Abdelhameed
7,1968 gold badges25 silver badges49 bronze badges
7,1968 gold badges25 silver badges49 bronze badges
asked Mar 26 at 1:44
xxishxxish
275 bronze badges
275 bronze badges
4
Looks like all you have to do is remove the spaces from your regex pattern. Why did you add them in the first place?
– Ahmed Abdelhameed
Mar 26 at 1:46
if we have answered your question, could you please accept an answer/upvote as detailed in: stackoverflow.com/help/someone-answers
– Allan
Apr 2 at 0:53
add a comment |
4
Looks like all you have to do is remove the spaces from your regex pattern. Why did you add them in the first place?
– Ahmed Abdelhameed
Mar 26 at 1:46
if we have answered your question, could you please accept an answer/upvote as detailed in: stackoverflow.com/help/someone-answers
– Allan
Apr 2 at 0:53
4
4
Looks like all you have to do is remove the spaces from your regex pattern. Why did you add them in the first place?
– Ahmed Abdelhameed
Mar 26 at 1:46
Looks like all you have to do is remove the spaces from your regex pattern. Why did you add them in the first place?
– Ahmed Abdelhameed
Mar 26 at 1:46
if we have answered your question, could you please accept an answer/upvote as detailed in: stackoverflow.com/help/someone-answers
– Allan
Apr 2 at 0:53
if we have answered your question, could you please accept an answer/upvote as detailed in: stackoverflow.com/help/someone-answers
– Allan
Apr 2 at 0:53
add a comment |
1 Answer
1
active
oldest
votes
As it has been mentioned in the comment, spaces are characters that will be interpreted literally in your regex pattern.
Therefore in this part of your regex:
([.] [0-9] 1,3)
- a space is expected between
.
and[0-9]
, - the same goes for after
[0-9]
where the regex would match1
to3
spaces.
This being said, for readability purpose you have several way to construct your regex.
1) Put the comments out of the regex:
string myregex = @"s" // Match any whitespace once
+ @"n" // Match one newline character
+ @"[a-zA-Z]"; // Match any letter
2) Add comments within your regex by using the syntax (?#comment)
needle(?# this will find a needle)
Example
3) Activate free-spacing mode within your regex:
nee # this will find a nee...
dle # ...dle (the split means nothing when white-space is ignored)
doc: https://www.regular-expressions.info/freespacing.html
Example
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%2f55348715%2fhow-to-filter-out-certain-combinations%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As it has been mentioned in the comment, spaces are characters that will be interpreted literally in your regex pattern.
Therefore in this part of your regex:
([.] [0-9] 1,3)
- a space is expected between
.
and[0-9]
, - the same goes for after
[0-9]
where the regex would match1
to3
spaces.
This being said, for readability purpose you have several way to construct your regex.
1) Put the comments out of the regex:
string myregex = @"s" // Match any whitespace once
+ @"n" // Match one newline character
+ @"[a-zA-Z]"; // Match any letter
2) Add comments within your regex by using the syntax (?#comment)
needle(?# this will find a needle)
Example
3) Activate free-spacing mode within your regex:
nee # this will find a nee...
dle # ...dle (the split means nothing when white-space is ignored)
doc: https://www.regular-expressions.info/freespacing.html
Example
add a comment |
As it has been mentioned in the comment, spaces are characters that will be interpreted literally in your regex pattern.
Therefore in this part of your regex:
([.] [0-9] 1,3)
- a space is expected between
.
and[0-9]
, - the same goes for after
[0-9]
where the regex would match1
to3
spaces.
This being said, for readability purpose you have several way to construct your regex.
1) Put the comments out of the regex:
string myregex = @"s" // Match any whitespace once
+ @"n" // Match one newline character
+ @"[a-zA-Z]"; // Match any letter
2) Add comments within your regex by using the syntax (?#comment)
needle(?# this will find a needle)
Example
3) Activate free-spacing mode within your regex:
nee # this will find a nee...
dle # ...dle (the split means nothing when white-space is ignored)
doc: https://www.regular-expressions.info/freespacing.html
Example
add a comment |
As it has been mentioned in the comment, spaces are characters that will be interpreted literally in your regex pattern.
Therefore in this part of your regex:
([.] [0-9] 1,3)
- a space is expected between
.
and[0-9]
, - the same goes for after
[0-9]
where the regex would match1
to3
spaces.
This being said, for readability purpose you have several way to construct your regex.
1) Put the comments out of the regex:
string myregex = @"s" // Match any whitespace once
+ @"n" // Match one newline character
+ @"[a-zA-Z]"; // Match any letter
2) Add comments within your regex by using the syntax (?#comment)
needle(?# this will find a needle)
Example
3) Activate free-spacing mode within your regex:
nee # this will find a nee...
dle # ...dle (the split means nothing when white-space is ignored)
doc: https://www.regular-expressions.info/freespacing.html
Example
As it has been mentioned in the comment, spaces are characters that will be interpreted literally in your regex pattern.
Therefore in this part of your regex:
([.] [0-9] 1,3)
- a space is expected between
.
and[0-9]
, - the same goes for after
[0-9]
where the regex would match1
to3
spaces.
This being said, for readability purpose you have several way to construct your regex.
1) Put the comments out of the regex:
string myregex = @"s" // Match any whitespace once
+ @"n" // Match one newline character
+ @"[a-zA-Z]"; // Match any letter
2) Add comments within your regex by using the syntax (?#comment)
needle(?# this will find a needle)
Example
3) Activate free-spacing mode within your regex:
nee # this will find a nee...
dle # ...dle (the split means nothing when white-space is ignored)
doc: https://www.regular-expressions.info/freespacing.html
Example
edited Mar 26 at 3:26
answered Mar 26 at 2:14
AllanAllan
9,8673 gold badges15 silver badges37 bronze badges
9,8673 gold badges15 silver badges37 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55348715%2fhow-to-filter-out-certain-combinations%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
4
Looks like all you have to do is remove the spaces from your regex pattern. Why did you add them in the first place?
– Ahmed Abdelhameed
Mar 26 at 1:46
if we have answered your question, could you please accept an answer/upvote as detailed in: stackoverflow.com/help/someone-answers
– Allan
Apr 2 at 0:53