validation - How to validate input value in a TextField in Java ME -


i writing simple srms, , need validate input user if matches criteria depending on field, e.g. email field or phone field. app run in featured phone , using java me sdk virtual machine testing.

what best way so, best way validate input , if input not meet criteria, should user notified or value has entered set null again.

public void name() {     boolean namevalid = false;     display = display.getdisplay(this);     nameform = new form("student record management (1/4");     textfield firstname = new textfield("first name(s)", "", 20, textfield.any);     textfield lastname = new textfield("last name", "", 20, textfield.any);     textfield personnumber = new textfield("person number", "", 10, textfield.numeric);     = new command("back", command.back, 1);     next = new command("continue", command.item, 2);      nameform.append(firstname);     nameform.append(lastname);     nameform.append(personnumber);     nameform.addcommand(back);     nameform.addcommand(next);     nameform.setitemstatelistener(this);     nameform.setcommandlistener(this);     display.setcurrent(nameform);      if (firstname.tostring().length() > 0) {         namevalid = true;     } } 

the person started code has implemented commandlistener , iteststatelistener.

i not sure second 1 , has abstract method filled called itemstatechanged(item item) supposed check changes , validate in here ?

the itemstatelistener notifies application of changes in form items. item itemstatechanged(item item) method called when item in form changed by user or when item.notifystatechanged() called in item. argument item (textfield, datefield, ect) changed value.

i recommend call validation method inside both commandaction , itemstatelistener. in itemstatechanged current item (the 1 received in argument) should checked. in commandaction every field should checked. way every item validated in every situation.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -