Create Validation Regular Expression
Hello! I want to ask a simple question about regular expression in asp.net.
the question is how to handle "javascript" as a single word by creating a validation expression for regular expression server control.
Please, I need the answer as soon as possible.
Thank's
Please clarify exactly what you are looking for. Are you trying to verify javascript code with a regex? That's rather complicated.
Or are you just trying to verify that some string is exactly the text "javascript", which is trivial and doesn't require a regex.
please provide a couple of examples of positive matchs and negative ones.
As you've expressed it seems unnecessary to use regular expression to accomplish your task: it's like to kill a fly with a H-Bomb.
This places the match into a group called 'script', it allows for either Javascript or javascript. If the character ':' exists it will throw it away, otherwise it does not have to be there.
You don't necessarily have to access the match group by name, but in the future if you have multiple groups, its nice to access them by name instead of number.
// using System.Text.RegularExpressions;
/// <summary>/// Regular expression built for C# on: Tue, Jul 18, 2006, 08:44:15 AM/// Using Expresso Version: 2.1.2150, http://www.ultrapico.com/// /// A description of the regular expression:/// /// [script]: A named capture group. [Javascript]/// Javascript/// Match expression but don't capture it. [\:?]/// :, zero or one repetitions/// /// /// </summary>public Regex MyRegex = new Regex( @"(?<script>Javascript)(?:\:?)", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled );Basically, what you want is just ". Any character in the regex expression that does not have a special meaning just matches that same character. (and nothing there has a special meaning).
Except that's no what you want. You want to match any string as long as it does NOT contain ". That's a bit different. And I'm not really sure how to do it.
my application have a shared file have the Validation Expressions for all the application pages, because of that i need the expression to solve this problem.
as you know when the user enter Javascript followed by ":" and write any java script code, some errors occur in the system, so because of these problems i need to deny the user of enter this work.