다음과 같은 문자열이 주어집니다 :Javascript 또는 jQuery에서 문자열 시작 부분의 공백을 감지하는 방법은 무엇입니까?
htmlStr1 = " <div>This is a string with whitespace in the beginning</div> ";
htmlStr2 = "<div>This is a string with no whitespace in the beginning</div> ";
이 문자열에 공백이 처음부터 있는지 만 탐지 할 수있는 함수를 작성하는 방법이 있습니까?
예 : 다음을 수행해야합니다.
alert(checkBeginningWhiteSpace(htmlStr1)); // should return "true"
alert(checkBeginningWhiteSpace(htmlStr2)); // should return "false"
이것은 공백이 하나만 있는지 확인합니다./^ \ s +/ –
정말로 첫 번째 문자 만 검사하면 문자열이 공백으로 시작하는지 확인할 수 있습니다. – Rafael
라파엘 맞아요. 공백 하나만 검사해야했습니다. –