2

I was hoping someone could point me in the right direction. I'm looking for a resource that can show me how to validate user input within forms(contact forms) similar to JavaScript validation. I have searched all over the web and cant seem to find anything.

thanks everyone

MADPADGE
  • 113
  • 2
  • 12
  • [Similar question](http://stackoverflow.com/questions/2763022/android-how-can-i-validate-edittext-input) (for EditTexts) – keyser May 14 '12 at 15:02

3 Answers3

1

You can, for example, check the input using Regex... "Regex on Google"

"Regex Android" on Google

Topic about an example of handling Regex, in android

Community
  • 1
  • 1
Jeje Doudou
  • 1,707
  • 1
  • 16
  • 24
1

Use regular expression, here is an excellent tutorial : Validation

Imran Rana
  • 11,899
  • 7
  • 45
  • 51
  • @MADPADGE if you want to check something like if username is available or not then, you need to use a database with list of users and run a query(using cursor) with current user input to fetch existing name and check validity. – Imran Rana May 14 '12 at 15:13
  • Ok thanks. I have not built a database yet, however that will be useful. Currently I am looking to check whether the user has entered data in the desired fields, and if they fit the specified formatting. the link you provided looks like it will assist me. Is it possible validate checkboxes and radio buttons? I only see EditText validation. – MADPADGE May 14 '12 at 15:22
  • Yes, it is possible. use **`checkBox.isChecked()`** for checkbox validation and for radio buttons group use **`getCheckedRadioButtonId()`** method which returns -1 if none is selected. – Imran Rana May 14 '12 at 16:01
0

if u re looking sfor some simple validation , then consider your java file as simple javascript function .

step 1 : make a base class with all the validation function like

    public boolean isEmail(String fieldValue) 
        {
            Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
            Matcher m = p.matcher(fieldValue);
            if(!m.matches()) {
                return false;
            } else {
                return true;
            }
        }

step 2 : initialize a variable valid = true ;

step 3 : initialize an object for this validator class in your desired form page

step 4 : call a validation function on click of form submit button

step 5 : use the object to call the validation function on your desired page and according to the result it gives , set valid = false or leave ,

step 6 : finally 

    if(valid) 

        { ... submit the form ...}