how to create EditText allow only Alphabets capital and smal

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

how to create EditText allow only Alphabets capital and smal

Postby mr_muskuraha » Mon Mar 22, 2010 12:21 pm

dear friends,

i want to create EditText Field for State

i dont want user to enter numbers and other special characters in it can any one guide me how can i create EditText that must allow Alphabets in small and caps both only.?

any help would be appriciated.
mr_muskuraha
Senior Developer
Senior Developer
 
Posts: 142
Joined: Wed Jan 13, 2010 8:49 am

Top

ok

Postby mr_muskuraha » Mon Mar 22, 2010 12:53 pm

the only way i found my self is using regular expression is there any other built in way to achieve this?


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. EditText state = (EditText) findViewById(R.id.txtState);
  2.  
  3.                                
  4.  
  5.                                
  6.  
  7.                                 Pattern ps = Pattern.compile("^[a-zA-Z ]+$");
  8.  
  9.                                 Matcher ms = ps.matcher(state.getText().toString());
  10.  
  11.                                 boolean bs = ms.matches();
  12.  
  13.                                 if (bs == false) {
  14.  
  15.                                         if (ErrorMessage.contains("invalid"))
  16.  
  17.                                                 ErrorMessage = ErrorMessage + "state,";
  18.  
  19.                                         else
  20.  
  21.                                                 ErrorMessage = ErrorMessage + "invalid state,";
  22.  
  23.                                        
  24.  
  25.                                 }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
mr_muskuraha
Senior Developer
Senior Developer
 
Posts: 142
Joined: Wed Jan 13, 2010 8:49 am

Postby asolanki » Tue Mar 23, 2010 12:41 pm

Hi!!!

in the edit text you can find property called "digits"
you can pass string value to it

e.g. if you want only 0-9 digits then pass
digits : 0123456789
asolanki
Senior Developer
Senior Developer
 
Posts: 151
Joined: Thu Jan 08, 2009 7:32 am

Postby mistajase » Sun Mar 28, 2010 10:03 pm

asolanki wrote:Hi!!!

in the edit text you can find property called "digits"
you can pass string value to it

e.g. if you want only 0-9 digits then pass
digits : 0123456789


This worked for me, but now the soft keyboard doesn't appear on touch.

how can i get round this?
mistajase
Junior Developer
Junior Developer
 
Posts: 20
Joined: Thu Nov 26, 2009 4:28 am

ok

Postby mr_muskuraha » Mon Mar 29, 2010 7:10 am

have you tried using regular expression as i did??
mr_muskuraha
Senior Developer
Senior Developer
 
Posts: 142
Joined: Wed Jan 13, 2010 8:49 am

Postby mistajase » Mon Mar 29, 2010 3:18 pm

No, i was going to try that but I found another solution! :D

in your xml layout try adding -

Code: Select all
android:imeOptions="actionNext"
android:inputType="text"


so the whole editText should something look like -

Code: Select all
<EditText android:id="@+id/GroupET"
android:maxLines="1" android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/GroupET"
android:imeOptions="actionNext"
android:inputType="text"
android:digits="@string/keyboardfilter">
</EditText>


This works perfectly for me, the spacebar is disabled and the soft keyboard now appears on touch!
mistajase
Junior Developer
Junior Developer
 
Posts: 20
Joined: Thu Nov 26, 2009 4:28 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests