How can I check the input of a textbox?

I am creating a program and I need to validate my text boxes. For the program, the user needs to add a phrase. But I'm not sure how to make sure the user actually entered the phrase, the phrase is not (for example) skldkfdl, or that there is no space.

+1


source to share


2 answers


Strings in Java

You can do String.Trim () to get rid of trailing whitespace first ...



then do String.IndexOf ("") to check for space.

If the function returns -1, it means that there is no space in the string.

0


source


This is performed provided that you are using VB.Net. Add an event handler for the event where you want to validate the text, such as when the submit button is clicked. You can use CancelEventHandler to cancel the click. In an event handler, if you are looking for a simple confirmation, you can use if-statements to check for some simple conditions, for example, if you just want to check "if input.equals (password)". Take a look here for an example using CancelEventHandler.
If you're looking for a more complex validation, you'll want to use regular expressions. This page can help you get started
Checking to see if something is a "phrase" as in correct English would be very difficult. You will need to make sure all words are in the dictionary and then you will need to check the correct grammar, which is incredibly difficult given the rules of English grammar. You can simplify your approach depending on your problem. For example, maybe just check if there are any strange characters, that there is more than one space, and that each word contains a vowel.



0


source







All Articles