I'm trying screen words in a textbox

Results 1 to 2 of 2

Thread: I'm trying screen words in a textbox

  1. #1
    Join Date
    Dec 1969

    Default I'm trying screen words in a textbox

    &nbsp;<BR><BR>I&#039;m trying to validate words in a textbox, what would be the best way of do this I have tried an array, but if more the one of the words are submitted then the if statement fails. if I type in "forget and yes" it fails the condition) I have a total of eight words so a combination of statements && and or statements will not be pretty. P.S. I understand way it doesn&#039;t work I just can&#039;t figure a way to make it work. I&#039;m sure there is some type of string method I can use to make this work (I hope).<BR><BR>----------------------------code-------------------------------<BR>string[] words = new string[8]{"yes","no","forget"};<BR><BR>if (<BR>Message.Text = words.GetValue(0).ToString()<BR>Message.Text = words.GetValue(1).ToString()<BR>Message.Text = words.GetValue(2).ToString()<BR>)<BR>{<BR> Response.write("sorry can&#039;t use these words");<BR><BR>}<BR>(

  2. #2
    Join Date
    Dec 1969

    Default RE: I'm trying screen words in a textbox

    Look at regular expressions. Should not be too terribly complex as far as regexs go. The search pattern might be something like [&#060;word&#062;&#124&#060;word&#062;&#124....&#12 4&#060;word&#062;&#124s]+ (any of the &#060;word&#062;s or whitespaces, one or more times.<BR><BR>Or you could get the textbox value, do a split on whitespace, and loop through the resulting array.<BR><BR>Very rough c#-ish pseudocode<BR>strBlah[] = textbox.text.split(" ")<BR>foreach string strWord in strBlah<BR>&nbsp;&nbsp;if strWord != &#060;word&#062; && strWord != &#060;word2&#062; ...<BR>&nbsp;&nbsp;&nbsp;&nbsp;return invalid word message.<BR><BR>O&#039;Cary<BR>www.ocary.com<BR><B R><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts