Regex not working validation control - asp.net

I am new to Regex, I have a Regex expression in an asp.net ExpressionValidator with this expression in it to validate an email address.
The problem is it won't validate the email when the us.af.mil is in capital letters. The error I get is:
unexpected qualifier
All the other times all it recognizes is the lower case part of the email. I have tried several other variations on the code and nothing works. I am sure I am leaving something out but not sure what. Listed below are some of the variations. Hope someone can tell me what I am leaving out.
\w+([-+.']\w+)*#(?i:(us.af.mil))
\w+([-+.']\w+)*#(us.af.mil)|(US.AF.MIL)
\w+([-+.']\w+)*#uUsS.aAfF.mMiIlL
\w+([-+.']\w+)*#(?i)(us.af.mil)

Related

Email validation in asp net web form

Just curious to know, I am using TextMode="Email" in asp net web form which works as expected however when we provide "info" as a part of first word(Before #) like "info#xyz.com" or "jyo.info#xyz.com" or "jyoinfo#xyz.com" then It says invalid email. I believe it is because the first word(Before #) contains "info"(all small) but making any single or all character of "info" in capital letter work fine. Anyone please explain the reason for this behavior and if i am somewhere wrong then please guide me in right direction.
You can specify your own regular expression to make the email test non-case sensitive. Below is a pretty decent regex for email testing (not too aggressive).
^[a-zA-Z0-9_.+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$

Regex password validation working fine on regex verification sites but not on mine

I have the following Regex code that works fine on regex verification code but not on my website (built with ASP.NET MVC). It validates the length and numeric but not the absence of special characters.
My regex: /^(?=.*[!###$&](?=.*[A-Z]))(?=.*[0-9])(?=.*[a-z]).{8,}$/
On my website Toto1234 is considered fine but that does not be the case since it does not contain a special character.
Basically I was checking on my view but did not make any change on my model. My model had a Regex that was not checking for special characters. But on my view, there is script that checks if the password matches the regex.
Edit: The solution, to be more clear is to make sure the view model or class is decorated with the right Regex. Any regex check and/or validation in the view my work temporary before you try to submit your form.
In my case since I had to different regex (in my view --via jquery-- and my model), client side verification worked because I have the right regex. But server side verification did not. I had to make sure I had the right regex on my class as well.
Hope this is more clear.

How do I validate a zip code in visual basic?

I am supposed to use the regularExpressionValidator to verify a ZIP code for a basic webpage I'm making. If the Zip code is valid, the submit button's click event procedure should display the message "Your ZIP code is" followed by the ZIP code and a period.
I don't know how to do an "if" statement to check to see if the zip is valid or not
**Why does the value = 0 when I enter 60611-3456
...don't know how to do an "if" statement...
You were assigned to use a RegularExpressionValidator, and this sounds like homework. If so, it also sounds like the purpose of the assignment is to make this happen without writing any if statements at all.
The validator controls have a feature where a postback event will not occur if validation fails. You use a correct regular expression with a correctly configured validator control, and the code that shows the "Your zip code is..." message will never run. Configuring the validator control is the point of the assignment; you need to do that part on your own. But finding an acceptable regular expression is a distraction from the real learning, and so I don't mind just giving that to you:
^\d{5}(-\d{4})?$
The issue is that your regular expression indicates the four digits must exist if you have the dash. Generally that would be okay but since you're using an input mask the dash always exists, even when it's only five digits. Try the following expression.
ValidationExpression="\d{5}-?(\d{4})?$"
Hope it helps.

Adding IP Address to Email Validation RegEx

I am using the RegEx "^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*#[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+[.])*(\.[a-zA-Z]{2,17})$"to validate Email but my lead want to validate as per the Microsoft standard. SO i need to follow
http://msdn.microsoft.com/en-us/library/01escwtf(v=vs.100).aspx
In that everything working fine as per the standard but still i am facing the issues with
Valid: js#internal#proseware.com
Valid: j_9#[129.126.118.1]
the above mentioned mail ID is still returning as invalid. I tried using the regex used in that page
^(?("")(""[^""]+?""#)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])#))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$
but i am getting the error in the server page. Though I pasted the expression inside the validation Expression it can't able to accept the characters.
Note : am using ASP.Net validators for validating the email.
Description
To match both of those email addresses in your sample text, I think I would rewrite your expression like this:
[A-Z0-9._%#+-]+#(?:[A-Z0-9.-]+\.[A-Z]{2,4}|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\])
If you're looking to use this to validate a string which may contain only an email then you can add the start/end of string anchors ^ and $.
Example
Live Demo
Sample Text
Valid: js#internal#proseware.com Valid: j_9#[129.126.118.1]
Matches
[0][0] = js#internal#proseware.com
[1][0] = j_9#[129.126.118.1]

Asp.net validation expression for a string

I want to create a regular expression for subdomain like:
In the textbox user need to enter like
abc1.test.com
or
abc1s.test.com
Note: .test.com is always required at the end.
The variable part can contain any letter, alphabets etc
I dont know anything about regex so i ask this silly question. I googled it for more than 2 hours but dont find any good example.
Please note this is not a homework.
Any help is highly appreciated.
There are a number of useful resources on regex online, including:
http://regexpal.com/ - test out your regex
http://www.regular-expressions.info/reference.html - regex reference
http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/ - useful cheat sheet
I am sure other members will have better resources but these have sufficed for me in the past.
The following regex should work for you:
^((.+)(.test.com){1})$
the '.' is any character except new line
the '+' is one or more times
the '{1}' is exactly once
^[\d\w]+\.test\.com$ will work for your case.

Resources