2010-04-18 4 views

답변

2

trim function과 같은 것을 찾고 계십니까?

+1

네, 감사합니다! 사실 jQuery에는 내장 trim() 함수가 있습니다! –

+2

당신은 jQuery로 작업하고 있다고 말하지 않았습니다 - 더 많은 정보를 제공하면 가장 좋은 답변을 얻을 수 있습니다 ... jquery 유효성 검사 플러그는 빈 선택자를 제공합니다. http://docs.jquery.com/Plugins/Validation/blank – calumbrodie

+0

+1 맞습니다. 나는 그것을 언급 했어야했다. 감사합니다 : 공백! –

1

은 ...

String.prototype.trim = function() { 
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"); 
}; 

여기에 다음 http://javascript.crockford.com/remedial.html

참조 (트림 기능을 제공하기 위해) 어딘가에서이 기능을 포함

if (document.forms['id_of_form'].elements['id_of_input'].value.trim()=='') { 
    //do xyz 
} 
9
var str = document.getElementById("myInput").value; 
if (str.match(/^\s*$/)) { 
    // nothing, or nothing but whitespace 
} else { 
    // something 
} 
관련 문제