ASP regular expression only allow numbers bigin with either 7 o 8 - asp.net

I need a regular expressin in asp.net , that will check my account number field that only allows numbers that begins with a 7 or a 8.

[Edit] This will work for your given case. I have tested it in RegexBuddy.
^(?:7|8)\d{6}-\d{7}

You can try liks this (partial example)
^(7|8)

you can use Regex.IsMatch Method
if (Regex.IsMatch(AccountNumber, #"^[7-8]+$"))
Also, it will be helpful for you to go through these articles
Regular Expression Basic Syntax Reference
Learn how to write a Regular Expression

Exact solution to your 14-digit format:
^[78]\d{6}-\d{7}$

^[78][0-9]*
Expression should start with 7 or eight, then have 0 or more numbers.

you can try this one; I'm padding my answer here to go over the 130 character minimum length imposed by stack overflow
^[7-8]+$

Related

How to match a minimum number of regex groups or assertions?

OK regex nerds!
I am using regex lookahead assertions for password validation that is similar to the pattern described here:
\A(?=\w{6,10}\z)(?=[^a-z]*[a-z])(?=(?:[^A-Z]*[A-Z]){3})(?=\D*\d)
However, we want to only require that any 3 of the 4 assertions be valid - not necessarily all of them. Any thoughts on how this could be done?
To shorten any kind of pattern, factorize:
\A(?:
(?=\w{6,10}\z) (?=.*[a-z]) (?: (?:.*[A-Z]){3} | .*\d )
|
(?=.*\d) (?=(?:.*[A-Z]){3}) (?: .*[a-z] | \w{6,10}\z )
)
Note that you don't need a lookahead to test the last condition.
demo
Other way, where each condition is optional and that uses a named group to count (.net only):
\A
(?<c>(?=\w{6,10}\z))?
(?<c>(?=[^a-z]*[a-z]))?
(?<c>(?=(?:[^A-Z]*[A-Z]){3}))?
(?<c>(?=\D*\d))?
(?<-c>){3} # decrement c 3 times
(?(c)|(?!$)) # conditional: force the pattern to fail if too few conditions succeed.
demo
There's no "easy" way to do this in a single regular expression. The only way would be to define all possible permutations of the "three out of four" assertions - e.g.
\A(?=\w{6,10}\z)(?=[^a-z]*[a-z])(?=(?:[^A-Z]*[A-Z]){3})| # Maybe no digit
\A(?=[^a-z]*[a-z])(?=(?:[^A-Z]*[A-Z]){3})(?=\D*\d)| # Maybe wrong length
\A(?=\w{6,10}\z)(?=(?:[^A-Z]*[A-Z]){3})(?=\D*\d)| # Maybe no lower
\A(?=\w{6,10}\z)(?=[^a-z]*[a-z])(?=\D*\d) # Maybe not enough uppers
However, this mind-melting regex is clearly not a good solution.
A better approach would be to perform the four checks separately (with regex or otherwise), and count that there is at least three passed conditions.
...However, let's take a step back here and ask: Why are you doing this?? You're implementing a password entropy check. Based on your fuzzy rules, the following passwords are valid:
AAAa1
password1
LETmein
And the following passwords are invalid:
reallylongsecurepassword8374235359232
HorseBatteryStapleCorrect
I would strongly advise against such a bizarrely restrictive policy.
Brief
The easiest method would be to have separate regular expressions and check whether 3/4 of them are successful in your code's language. The only way to do this in regex is to present all cases. That being said, this is probably the easiest method (in regex) to present all options as it allows you to edit the patterns in one location (where they are defined) rather than multiple times (more prone to bugs). The DEFINE constructs in regex are seldom supported, but PCRE regex does.
You can also have your code generate each regex permutation. See this question about generating all permutations of a list in python
I don't know why you want to do this for passwords, it's considered malpractice, but, since you're asking for it, I figured I'd give you the easiest solution possible in regex... You really should only check minimum length (and complexity if you want [based on algorithms] to show the user how secure your system finds their password to be).
Code
(?(DEFINE)
(?<w>(?=\w{6,10}\z))
(?<l>(?=[^a-z]*[a-z]))
(?<u>(?=(?:[^A-Z]*[A-Z]){3}))
(?<d>(?=\D*\d))
)
\A(?:
(?&w)(?&l)(?&u)|
(?&w)(?&l)(?&d)|
(?&w)(?&u)(?&d)|
(?&l)(?&u)(?&d)
)
Note: The regex above uses the x modifier (ignore whitespace) so that we can nicely organize the content.

Hexadecimal to decimal in windbg

It looks like the default for WinDbg is to display ints in decimal and unsigned ints in hexadecimal.
Is there a way to show all in decimal?
I tried using the n command mentioned here
It gives me syntax error though:
:086> n[10]
^ Syntax error in 'n[10]'
Any idea what am I doing wrong?
It seems that you are using square brackets when you shouldn't. On the MSDN page, those square brackets are there to show that the radix argument is optional.
When the argument is left off, the current radix is displayed to you.
0:000> n
base is 10
When you provide the argument (with no square brackets) the current radix is changed and echoed back to you.
0:000> n 16
base is 16
A commonly used trick once the base is set is to use the ? (Evaluate Expression) command to convert numbers to the new base (in this example, base 16).
0:000> ? 0n10
Evaluate expression: 10 = 0000000a
0:000> ? 0y11
Evaluate expression: 11 = 00000003
To convert from hex (base 16) back to decimal:
0:000> ? a
Evaluate expression: 10 = 0000000a
Remember that once the base is set, both input and output are affected meaning that when you want to enter a number that isn't is the current base, you will need to specify the base as was done above in the final example. Further reading on how numbers are handled in the MASM-like syntax is available here.
But back to your original question...
Yes, n 10 should be enough to force numbers to be displayed in decimal. If for some reason there is a problem, you can always use the ? command as shown above to perform the conversion.
Extended article describing how WinDbg evaluates expressions (including details on the impact of the n command) available here:
https://www.osronline.com/article.cfm?id=540
try using the command:-
.enable_long_status 0

Regex for digits from 0 to 16 digits Only in ASP.net

I have a text field that is the user choose to enter data in it, it must be digits and must be less than or equal to 16 digits (Not more than that).
I have regular expression for digits,
ValidationExpression="^\d{10}$"
which is be exactly 10 digits. But how to modify it for my scenario?
I am embarrassed by such a simple question, but I got confused. If it is a duplicate question or somebody asked similar question, please let me know.
Note: I need the regex for ASP.net
Here is a good tutorial.
^\d{0,16}$
Note, that in .NET, \d can also match any Unicode character that represents a digit (see here). If you really just want the ASCII digits, use
^[0-9]{0,16}$
(Since I am not sure how you would set RegexOptions if that is possible at all in your case.)
The curly-brace quantifier is {min,max}, so {0,16} will do for your case.

Simple integer regular expression

I have ValidationRegularExpression="[0-9]" which only allows a single character. How do I make it allow between (and including) 1 and 7 digits? I tried [0-9]{1-7} but it didn't work.
You got the syntax almost correct: [0-9]{1,7}.
You can make your solution a bit more elegant (and culture-sensitive) by replacing [0-9] with the generic character group "decimal digit": \d (remember that other languages might use different characters for digits than 0-9).
And here's the documentation for future reference:
.NET Framework Regular Expressions
If you want to avoid leading zeros, you can use this:
^(?!0\d)\d{1,7}$
The first part is a negative lookahead assertion, that checks if there is a 0 followed by a number in the string. If so no match.
Check online here: http://regexr.com?2thtr

RegEx For Strong Password

I have the following password requirements:
1) Should be 6-15 characters in length
2) Should have atleast one lowercase character
3) Should have atleast one uppercase character
4) Should have atleast one number
5) Should have atleast one special character
6) Should not have spaces
Can anyone suggest me a RegEx for this requirement?
Not sure I would use a Regex for that : regex are not always the right tool for any possible kind of job...
Here, you specified a list of 6 requirements ; so, why not just use 6 different tests, one per requirement ?
Those 6 different tests, should I add, would be really simple -- while a Regex would be much harder to write (you asked for help -- you would probably not have for the 6 tests).
This would make your code a lot more easier to understand, I'd bet ;-)
And also : easier to maintain ; and easier to add/remove/change one of the condition corresponding to one of the requirements.
I'm not entirely sure what you mean by "special character" so I am interpreting this to mean \W, but you can change this if you want:
^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\W)\S{6,15}$
Regexlib.com has tons of examples for you and a searchable database of reg ex's.
1 => /^.{6,15}$/
2 => /[a-z]/
3 => /[A-Z]/
4 => /\d/
5 => /[#{special_chars_for_regex}]/
6 => /^\S*$/

Resources