What's the RegularExpression that validate more than one thing? - asp.net

I am trying to create a custom RegularExpressionValidator to validate the current expression
number(0-99).number(100-1000)\number(0-99).number(100-1000)
or
number(0-99).number(100-1000),number(0-99).number(100-1000)
I am trying to create this expression but it didn't work
^\-?\d+\.?\d+\(/|,)\-?\d+\.?\d+$
What's the correct expression?
Regards,

If you mean you need to match a \ or a , in a regular expression, then this should work:
[\\,]
The \ character needs to be escaped (with another \).
Putting this into your example above gives (I think)
^\-?\d+\.?\d+[\\,]\-?\d+\.?\d+$

Related

Regular Expressions, containing specific words

I need to specify that my user name has to start with one of two words, followed by a backslash. It can only accept the words cat or dog at the beggining and then a backslash is expected, for example:
cat\something
dog\something
Both are accepted. What's the regular expression for this? I've tried some regular expressions but I haven«t figured it out yet.
The solution is:
^cat\\.*|^dog\\.*
https://regex101.com/ is a great tool for testing and evaluating regular expressions.

How to pass exact string as parameter in robot framework

I have the follow test case :
Some function
    Given some condition
    When I go to "\\path\to\folder"
    Then I don't know
I want to use exact: **"\\\\path\to\folder"** as string in my keyword argument
When I use above string, I'm getting escaped value.
I tried to use:
r"\\path\to\folder"
'\\path\to\folder'
Thank you.
The backslash is an escape character in robot, so to send a backslash you must escape the backslash.
When I go to \\\\path\\to\\folder
One solution is to escape it once again:
When I go to \\\\path\\to\\folder
Or you can use:
When I go to ${/}${/}path${/}to${/}folder
which will pass \\path\to\folder.
Another way to do it is to use a python raw string and just Evaluate it:
${my_string} Evaluate r"a\\b"
Log To Console ${my_string}

Allow - (dash) in regular expression

I have the following regular expression but I want the text box to allow the dash character
^[0-9a-zA-Z \/_?:.,\s]+$
Anyone know how I can do this?
The dash needs to be the first/last character in the character class in order to be used literally:
^[-0-9a-zA-Z \/_?:.,\s]+$
^[0-9a-zA-Z \/_?:.,\s-]+$
You could also escape it, if not the first/last:
^[0-9a-zA-Z\- \/_?:.,\s]+$
Simple answer, user \- in character class.
^[0-9a-zA-Z\- \/_?:.,\s]+$
Escape it with \ like:
^[\-0-9a-zA-Z \/_?:.,\s]+$

Regular Expression Validator for Letters and Numbers only

What is the Regular Expression Validator for only Letters and Numbers in asp.net?
I need to enter only 0-9,a-z and A-Z. I don't want to allow any special characters single or double quotes etc. I am using asp.net 3.5 framework.
I tried ^[a-zA-Z0-9]+$ and ^[a-zA-Z0-9]*$. They are not working.
Any help will be appreciated.
Try the following.
^[a-zA-Z0-9]+$
go to this example and also alphanumerics for more
then try this
^[a-zA-Z0-9]*$
If length restriction is necessary use
^[a-zA-Z0-9]{0,50}$
This will match alphanumeric strings of 0 to 50 chars.
you can try this....
^[a-zA-Z0-9]+$
see more info at here
You can define a regular expression as follows,
Regex myRegularExpression = new Regex(" \b^[a-zA-Z0-9]+$\b");
be sure to include System.Text.RegularExpression
and then use the Regex to match it with your user-control as follows,
eg : if your user-control is a textbox
myRegularExpression.isMatch(myTextBox.Text);
Dear English speaking people. With all due respect. A-Z are not the only letters in the world. Please use \w instead of [A-Za-z0-9] if you support other languages in your apps

Regular expression not working after debugging

I have an ASP.NET website with a regular expression validator text box.
I have changed the expression in the regular expression validation property "validator expression" and after compiling (rebuild) and running, the validation CHANGEs are not reflecting.
The previous validation is working fine but the changed validation is not working.
Please help me!
edit:
First code:
([a-zA-Z0-9_-.]+)\#((base.co.uk)|(base.com)|(group.com))
Second code:
#"([a-zA-Z0-9_\-.]+)#((base\.co\.uk)|(base\.com)|(group\.com)|(arg\.co\.uk)|(arggroup\.com))"
Assuming your "first code" is a literal regex, you need to escape the hyphen in the character class with a backslash.
Your "second code" is a regex formatted as a C# verbatim string that will match an email address such as whatever#base.co.uk just fine. There is nothing wrong with this regex.
You'll have to post the code in which you are using this regex if it doesn't work the way you want.
In this part: [a-zA-Z0-9_\-.] you are escaping the hyphen. The proper way to put a hyphen in a regex character class is in first position (or it thinks it is part of a range):
[-a-zA-Z0-9_.]
Then you removed the backslash from before the #. In Perl the # would be taken as part of a list name, but in C# I am not sure what effect it would have to not escape it.
The escaping of the periods is also suspect. You might need to double them up: e.g. \\. Instead, what I would do for a period is use a character class: i.e. [.] Inside the character class the period loses its special meaning.
Try this:
#"([-a-zA-Z0-9_.]+)\#((base[.]co[.]uk)|(base[.]com)|(group[.]com)|(arg[.]co[.]uk)|(arggroup[.]com))"

Resources