2012-08-09 44 views
0

我在應用程序上工作,並且有一個帶有密碼字段的註冊表單。如何創建需要至少輸入一個字母字符的密碼字段

我的基本要求是強制用戶插入至少一個字母字符到密碼字段以使密碼可以接受。

請給我一個建議,我該怎麼做?

謝謝。

+0

你可以發佈你試過嗎? – 2012-08-09 05:39:48

+0

EdPassword.getText()。toString()。 – 2012-08-09 05:40:41

+0

我試圖找到是否有任何方法 – 2012-08-09 05:43:23

回答

1

我認爲你需要檢查的密碼字符串包含ATLEAST信像1234是不能接受的,但a123是可以接受的。

你可以做到這一點像

public boolean containsLetter(String s) { 
    if (s == null) 
     return false; 

    for (int i = 0; i < s.length(); i++){ 
     if(CharacterUtilities.isLetter(s.charAt(i))) 
      return true; 
    } 
    return false; 
} 
+0

我需要的好答案 – 2012-08-13 05:42:24

0

當它不包含密碼字符時強制將字段作爲焦點不是一個理想的功能。如果想要對用戶名字段進行更正,但由於密碼字段爲空白,不能切換到該字段。相反,禁用提交按鈕,直到滿足密碼字段至少有一個字符的條件。

使用僞代碼:

if(field.contents.string.length < 1) 
{ 
confirmButton.enabled = false; 
} 
else 
{ 
confirmationButton.enabled = true; 
} 
+0

不,這不是我的要求 – 2012-08-09 05:52:00

0

密碼文本框的onChange使用方法,比這種方法檢查密碼文本字段的長度,不要使用裝飾,因爲用戶可能需要的空間。

<field object>.getText().lenght != 0 -> Enable submit button. 

或者在提交時檢查密碼字段文本是否大於或等於您的最小限制。

protected boolean navigationClick(int status, int time) 
{ 
    Field f1 = getFieldWithFocus().getLeafFieldWithFocus(); 
    if(f1 == btn_login) 
    { 
     if(txtField_userName.getText().trim().equals("") || txtField_password.getText().trim().equals("")) 
     { 
      String str[] = new String[]{"OK"}; 
      ButtonPopup.ask("Email or password can not left blank !", str); 
     } 
     else 
     { 
      <Do your work here> 

     } 
    } 
    return super.navigationClick(status, time); 
} 
相關問題