Validation for Email, Web address and phone number, but bit tricky - android

I have three fields in my form
1] Email address
2] Phone number
3] Web address
I know how to give validation for all, but i have diff requirement
What i want is if all fields are null no validation is applicable(no need to check)
if 1 field is empty and rest are filed check for those filed only not empty filed
I don't know what to do with this thing,
need to check for null/empty if null no need to to check for validation if field is not null/empty then check for that field only not other field

You can do something like this
if (!emailAddressEditText.getText().toString().matches(""){
//Apply your validation
}
if (!phoneNumberEditText.getText().toString().matches("")){
//Apply your validation
}
if (!webAddressEditText.getText().toString().matches("")){
//Apply your validation
}
I hope this helps you

Related

Default value of user.getPhoneNumber() function firebase auth

I want to check if user with email authentication has a phone number set in user profile.
I try if(user.getPhoneNumber() == null{
//do this
}
but it is not working for me... So i want to know what is default value of it
or how can i make it in another way. Thank you :)
user.getPhoneNumber() returns a String. The default value is an empty String which is not null. Use either
if(TextUtils.isEmpty(user.getPhoneNumber())){
//do this
}
or
if("".equals(user.getPhoneNumber())){
//do this
}

(Appium) Using sendKeys to write a number in an input field which already has a +91 hardcoded as a prefix, does not enter the number correctly

It selects and copies the number which I am sending and sometimes enters it before the +91 which eventually results in an error.
Below is the code I am using to send a number in to the number input field.
WebElement number = driver.findElement(By.id("com.ulink.agrostar.debug:id/edt_enter_mobileNumber"));
number.sendKeys("7976358798");
You have to first check whether your edit field consist of predefined field like
"+91", If it is there you can override text like these.
if(element.getText().trim().equals("+91")) {
number.clear();
}
number.sendKeys("+91" + "7976358798");
It should work please check.

Android Saripaar Validator 2.0.3: How to check that one of the rules is valid

Trying to use Android Saripaar validator for case when only one of two rules is valid. For example:
#Empty // my custom rule
#Or
#Email(messageResId = R.string.useremail_wrong_pattern)
EditText etUserEmail;
In example above I need that etUserEmail can be empty (if user hasn't input anything in this field) or is valid email (if user has inputed email).
But example above don't work correctly. Even if user hasn't input anything, validator apply #Email rule to etUserEmail field.
Is there a way to implement this task?
Maybe, I need create custom rule for #Or annotation? Can somebody give this rule example?

How to set a part of validation in saripaar?

When I use android-saripaar I want to use only some of the validation. I used the ViewPager and had a dozen of EditText. Each page had some inputs. And I want to validate the inputs at every step.
For example, I had username and password at first step, and phone, email at the second. If user type in the invalid data at first step, validation worked.
Finally I find the answer in the ISSUE : https://github.com/ragunathjawahar/android-saripaar/issues/104#issuecomment-133822417

How to check for type?

In an Android app I've got a couple contacts from my contacts list. They can be either emails, phone numbers, or even other things. I now want to check which type it is and bind specific actions to them.
For example, if it is a type vnd.android.cursor.item/email_v2, I want to send a POST message with just the email field, and if it is a type vnd.android.cursor.item/phone_v2 I want to send a POST message with just the phone field.
Any ideas how I could check this?
I guess the way to go would be using overloading:
You implement multiple methods with different input parameters but the same name, such as:
checkContact(email_v2 email){ do things with email }
checkContact(phone_v2 phone){ do things with phone }
checkContact(String s){do things with random string }
I think you get my point.
If you want a simple if-statement, though:
if (contact instanceof vnd.android.cursor.item/email_v2){ do send }
You could try checking the class constant CONTENT_ITEM_TYPE for your different types, something like:
contact.CONTENT_ITEM_TYPE.equals("vnd.android.cursor.item/email_v2");

Categories

Resources