Regular Expressions in .NET
-
Can anyone help me? I`ve just started my adventure with .NET. I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid. My problem is that I want .NET show me which character (which character index in this incorrect string) is invalid. Can anyone help with this? conrados
-
Can anyone help me? I`ve just started my adventure with .NET. I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid. My problem is that I want .NET show me which character (which character index in this incorrect string) is invalid. Can anyone help with this? conrados
I think, and only i think.. that .NET not capable to do that... so you could do it manually... using the string methods and check if the string is numeric or not, then you could run the validation as an expression.... or you could ask the MSDN ...Miliaware ..Faris Madi -- modified at 20:16 Thursday 24th November, 2005
-
Can anyone help me? I`ve just started my adventure with .NET. I want use regular expression in my text box to validate text. For example reg. expression like this : "[0-9][0-9]-[0-9][0-9][0-9]" accepts only for example "43-456" text. What if I enter "54-8f5" ? .NET Regular Expressions tells me that this text is not correct. But it doesn`t tell me which character is invalid. My problem is that I want .NET show me which character (which character index in this incorrect string) is invalid. Can anyone help with this? conrados
As
militiaware
writes, theRegex
capabilities in .NET do not offer the option to find the place where theRegex
fails to match. However, you could write your own regular expression parser to find the "best match" to your string and, then, you will know which character failed. I recommend this book, especially Chapter 8, "Parsing Regular Expressions": Title: Building Parsers With Java ISBN: 0201719622 Though the code and examples are in Java, you can easily translate it to the .NET-supported language of your choice. The design of his parser has a bestMatch() method that will return the string that best matches your given input, in this case, "[0-9][0-9]-[0-9][0-9][0-9]". "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty