Rajesh Sharma
Rajesh Sharma

Reputation: 603

How to give validation in forms fields ,in android

I'm a newcomer to android.

I'm creating a registration form in android, and I want to apply validation of some fields, like mobile no., email, date, etc..

And I want to display a POPUP message, if fields don't match.

Upvotes: 0

Views: 2717

Answers (5)

Rajesh Sharma
Rajesh Sharma

Reputation: 603

I am not sure but its always work for me ,For validation purpose we should use Regular expression which is you can found in Utill.nio package in java.

Upvotes: 0

Ridcully
Ridcully

Reputation: 23655

For showing errors, use the TextEdits setError() method.

Upvotes: 0

u can have a look at this

and for your alert message

@SuppressWarnings("deprecation")
    public void showAlertDialog(Context context, String title, String message,
            Boolean status) {
        AlertDialog alertDialog = new AlertDialog.Builder(context).create();

        // Setting Dialog Title
        alertDialog.setTitle(title);

        // Setting Dialog Message
        alertDialog.setMessage(message);

        if(status != null)
            // Setting alert dialog icon
            //alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);

        // Setting OK Button
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            }
        });

        // Showing Alert Message
        alertDialog.show();
    }

Upvotes: 0

Venky
Venky

Reputation: 11107

You can create a text view in Xml and set its visibility as GONE then make your validation.. For example check mobile no length

    TextView tv=(textView)findViewById(R.id.textview);
    EditText et=(EditText)findViewById(R.id.edittext);
    mobile_number=et.getText().toString();
    if(mobile_number.length<10){
      tv.setVisibility(View.VISIBLE);
   }else{
     //Some Code
    }

For Dialog boxe check this

Upvotes: 1

Siten
Siten

Reputation: 4533

and form validation are apply from its xml file..

for temporary popup msg.. Toast.makeText(getApplicationContext(), "your msg", Toast.LENGTH_SHORT).show();

Upvotes: 1

Related Questions