java - Validate the string length in SWT Text -
i have many modules in project, in every module have text box.
i want validate input(alphabet). have write common method.
need examples.
thanks in advance.
listen swt.verify
on text
, check condition. if want prevent given input, e.doit = false
.
here example allows @ 10 characters in text
:
public static void main(string[] args) { display display = new display(); shell shell = new shell(); shell.settext("stackoverflow"); shell.setlayout(new gridlayout(1, false)); final text text = new text(shell, swt.border); text.addlistener(swt.verify, new listener() { @override public void handleevent(event e) { string olds = text.gettext(); string news = olds.substring(0, e.start) + e.text + olds.substring(e.end); if(news.length() > 10) e.doit = false; } }); shell.pack(); shell.open(); while (!shell.isdisposed()) { if (!display.readanddispatch()) { display.sleep(); } } display.dispose(); }
Comments
Post a Comment