How to validate that the entered text has a correct format, knowing that the document number has the following format 12345678-9
?
I have tried for the length of the string but I still need to force the user to enter the script, I have not found a reference on masks in android
.
String docIdentificacion= titDuiCon.getText().toString().trim();
if(docIdentificacion.length<11){
//aqui muestro un error
}
You could do it in the following way
Use
contains("-")
to verify that the String contains the-
You should perform the check through a regular expression, here you will find more explanation of the rules:
For your case it would be of the type ^\d{8}+-\d{1} because it contains 8 starting digits (^\d{8}) then follows a - and then another digit (\d{1}) .
Using android Studio there is a very interesting feature, you locate yourself in the expression and give it Alt+Enter and a "Check RegExp" option will appear in which you can test if a value matches the expression you have.