Dhamodharan
Dhamodharan

Reputation: 305

Allow accent character in Edittext using digits Android

I am using Edittext which is allowed to specific characters. Like a-z A-Z 0-9 and Special characters like )&'(".

For the above requirement I used digits in Edittext to restrict rest of the other special characters getting typed.

The digits not supported ' & " chars so I used html code &apos ; &amp ; &quot ; respectively.

Now the problem is I want to allow accent characters too. I found the html code for accent Á is &Aacute ; but digits is showing error like

" The entity "Aacute" was referenced, but not declared. ".

Kindly provide any solution for this or Is there any solution to allow accent character with a-z,A-Z,0-9 and 5 special character )&'(" in Edittext?

Upvotes: 0

Views: 1564

Answers (2)

King of Masses
King of Masses

Reputation: 18775

much easier:

    <EditText
        android:digits="0123456789qwertzuiopasdfghjklyxcvbnmQWERTZUIOPASDFGHJKLYXCVBNM"
        android:inputType="text" />

Here in this digits: add your accent characters too

Just a word of caution, the characters mentioned in the android:digits will only be displayed, so just be careful not to miss some out :)

Upvotes: 0

Kartheek
Kartheek

Reputation: 7214

InputFilter filter = new InputFilter() { 
    public CharSequence filter(CharSequence source, int start, int end, 
    Spanned dest, int dstart, int dend) { 
            for (int i = start; i < end; i++) { 
               if ( !Character.isLetterOrDigit(source.charAt(i)) || Character.toString(source.charAt(i)) .equals(")") || 
                 !Character.toString(source.charAt(i)) .equals("(")  ||
                !Character.toString(source.charAt(i)) .equals("\'")  ||
                !Character.toString(source.charAt(i)) .equals("&")  ||
                !Character.toString(source.charAt(i)) .equals("&")) { 
                            return ""; 
                    } 
            } 
            return null; 
    } 
}; 

edit.setFilters(new InputFilter[]{filter}); 

Upvotes: 1

Related Questions