|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
regular expressionsneed to verify a string against reg exp. to allow only characters and apostrophe and hyphen
using : ======== Function RegExpValidate(sInput,sPattern) as boolean Dim RegexObj as Regex = New Regex("regularexpression") return Regex.IsMatch(sInput,sPattern) End Function calling with: ============== RegExpValidate(MyString,"[a-zA-Z'-]") but pattern isn't working. any help ???
Show quote
Hide quote
"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> schrieb: \\\> need to verify a string against reg exp. to allow only characters and > apostrophe and hyphen > > using : > ======== > Function RegExpValidate(sInput,sPattern) as boolean > Dim RegexObj as Regex = New Regex("regularexpression") > return Regex.IsMatch(sInput,sPattern) > End Function > > calling with: > ============== > RegExpValidate(MyString,"[a-zA-Z'-]") Dim IsMatch As Boolean = _ Regex.IsMatch(<Input>, "^[a-zA-Z'-]*$") /// You do not need to instantiate 'Regex' because 'IsMatch' is a shared method of the 'Regex' class. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> The hyphen is a special character in a set, you have to escape it:
[a-zA-Z'\-] Jon Paal wrote: Show quoteHide quote > need to verify a string against reg exp. to allow only characters and apostrophe and hyphen > > using : > ======== > Function RegExpValidate(sInput,sPattern) as boolean > Dim RegexObj as Regex = New Regex("regularexpression") > return Regex.IsMatch(sInput,sPattern) > End Function > > calling with: > ============== > RegExpValidate(MyString,"[a-zA-Z'-]") > > but pattern isn't working. any help ??? On 2006-05-06, Göran Andersson <gu***@guffa.com> wrote:
> The hyphen is a special character in a set, you have to escape it: You don't need to escape it if it appears at the end (or beginning) of the set.> > [a-zA-Z'\-] I suspect the OP is having problems with false positives rather than false negatives. The original Regex will match if any character in the string matches, rather than all. Presumably he wants either... ^[a-zA-Z'-]+$ ^[a-zA-Z'-]*$ depending on whether an empty string should match. Show quoteHide quote > > Jon Paal wrote: >> need to verify a string against reg exp. to allow only characters and apostrophe and hyphen >> >> using : >> ======== >> Function RegExpValidate(sInput,sPattern) as boolean >> Dim RegexObj as Regex = New Regex("regularexpression") >> return Regex.IsMatch(sInput,sPattern) >> End Function >> >> calling with: >> ============== >> RegExpValidate(MyString,"[a-zA-Z'-]") >> >> but pattern isn't working. any help ??? david wrote:
> On 2006-05-06, Göran Andersson <gu***@guffa.com> wrote: Ah. Then that's not the problem.>> The hyphen is a special character in a set, you have to escape it: >> >> [a-zA-Z'\-] > > You don't need to escape it if it appears at the end (or beginning) of the set. I would suggest that it's a good idea to escape it anyway. If you decide to add a character to the end of the set and forget to escape the hyphen, it would behave very unexpectedly, and it could take a lot of testing to realise the reason. :) > I suspect the OP is having problems with false positives rather than True, that is probably the reason why it "isn't working", as the OP put > false negatives. The original Regex will match if any character in the > string matches, rather than all. Presumably he wants either... > > ^[a-zA-Z'-]+$ > ^[a-zA-Z'-]*$ > > depending on whether an empty string should match. it... :) Show quoteHide quote >> Jon Paal wrote: >>> need to verify a string against reg exp. to allow only characters and apostrophe and hyphen >>> >>> using : >>> ======== >>> Function RegExpValidate(sInput,sPattern) as boolean >>> Dim RegexObj as Regex = New Regex("regularexpression") >>> return Regex.IsMatch(sInput,sPattern) >>> End Function >>> >>> calling with: >>> ============== >>> RegExpValidate(MyString,"[a-zA-Z'-]") >>> >>> but pattern isn't working. any help ???
SMTP won't send until thread terminates
How getting eventhandler attached to an event? Simple word count Which one is the Bluetooth DLL? ADODB custom wrapper Silly combo box question Threading so restricted? Win32API - FindFirstFile() in VB.NET My app as system process Simple TCP communications examples |
|||||||||||||||||||||||