android - How can i create my own editText with customised validation types? -
i want create own edit text field ,which used multiple entries user different set of required validations(email,phone,credit card,mixed chars).
try this:
for creditcard:
public boolean isvalid(edittext et) { try { return validatecardnumber(et.gettext().tostring()); } catch (exception e) { return false; } } public static boolean validatecardnumber(string cardnumber) throws numberformatexception { int sum = 0, digit, addend = 0; boolean doubled = false; (int = cardnumber.length () - 1; >= 0; i--) { digit = integer.parseint (cardnumber.substring (i, + 1)); if (doubled) { addend = digit * 2; if (addend > 9) { addend -= 9; } } else { addend = digit; } sum += addend; doubled = !doubled; } return (sum % 10) == 0; }
for ipaddress:
public ipaddressvalidator(string _customerrormessage) { super(_customerrormessage, build.version.sdk_int>=8?patterns.ip_address:pattern.compile( "((25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(25[0-5]|2[0-4]" + "[0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]" + "[0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}" + "|[1-9][0-9]|[0-9]))")); }
check example application more details:here
Comments
Post a Comment