본문 바로가기

Dev Platfrom/01. Android

EditText 특수문자 제한

EditText 특수문자 제한


1. EditText 특수문자 제한 예제 소스

mTopicComment = (EditText) findViewById(R.id.topic_add_comment);
		TextWatcher watcher = new TextWatcher() {
			
			String text;
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
			}
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				text = s.toString();
			}
			@Override
			public void afterTextChanged(Editable s) {
				int length = s.toString().length();
				if( length > 0 ){
					Pattern ps = Pattern.compile("^[a-zA-Z0-9ㄱ-ㅎ가-흐]+$");//영문, 숫자, 한글만 허용
					if(!ps.matcher(s).matches()){
						mTopicComment.setText(text);
						mTopicComment.setSelection(mTopicComment.length());
					}
				}
			}
		};
mTopicComment.addTextChangedListener(watcher);

 

2. 미친 삼성키보드 ( . ) 처리

Pattern ps = Pattern.compile("^[a-zA-Z0-9ㄱ-ㅎ가-흐ㄱ-ㅣ가-힣ᆢᆞ]+$"); 코드 부분에 이와 같이 처리하면 삼성키보드에서 . 을 처리 할 수 있다.

3. EditText  키보드 관련(패스워드) : http://www.androidpub.com/49420

 

'Dev Platfrom > 01. Android' 카테고리의 다른 글

SNS 연동  (0) 2012.10.16
BitMap / BitmapFactory 속성  (0) 2012.10.16
Android WebView  (0) 2012.10.12
App(앱)와 WebVew(웹) 간의 데이터(data) 통신  (0) 2012.10.12
Android ADB를 이용한 패킷 캡처  (1) 2012.09.26