Checking Usernames IS there an apI?
What's the best way to do this?
Just seen Pattern class, is this a good way to do it?
Just want to check that a username doesn't contain any characters apart from letters, numbers and underscores basically.
What's the best way to do this?
Just seen Pattern class, is this a good way to do it?
Just want to check that a username doesn't contain any characters apart from letters, numbers and underscores basically.
> What's the best way to do this?
>
> Just seen Pattern class, is this a good way to do
> it?
>
> Just want to check that a username doesn't contain
> any characters apart from letters, numbers and
> underscores basically.
You can try like this :
public void keyTyped(KeyEvent e)
{
try
{
char c = e.getKeyChar();
if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE))) || cmbDocPerPage.getEditor().getItem().toString().length()>=3)
{
getToolkit().beep();
e.consume();
}
}catch(Exception ex)
{}
}
Hope this will help you.
if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))) || cmbDocPerPage.getEditor().getItem().toString().length()>=3 )
KeyEvent.VK_[whatever] is meant to be compared with a key code, not a char. Also, getKeyCode() will always return KeyEvent.VK_UNDEFINED for key typed events.