2009-09-11 2 views

답변

33

당신은 유효성에 대한 테스트를 찾고 있다면 :

// from string start to end, only contains '-' "whitespace" or 'a'-'z' 
someString.match(/^[-\sa-zA-Z]+$/) 

또는 부정 ". 문자열 문자, 공백 및 하이픈을 포함 할 수 있습니다"

// has some invalid character not '-' "whitespace" or 'a'-'z' 
someString.match(/[^-\sa-zA-Z]/) 
+0

가장 포괄적 인 대답. +1 –

-2
if(someString.match(/[a-z -]+/i){ 
    // it's valid 
} 
+0

가 – inkedmn

+0

regexp를 다음과 같이 변경하십시오 :/[^ a-z \ -] +/i – Eimantas

+0

Eimantas - 정규 표현식을 변경할 필요가 없습니다 – inkedmn

관련 문제