sam*_*ist 3 javascript regex string
如果给定字符串只有一个特定字符但该字符出现的次数,我想返回true.
例子:
// checking for 's'
'ssssss' -> true
'sss s' -> false
'so' -> false
Run Code Online (Sandbox Code Playgroud)
检查一下
<div class="container">
<form action="javascript:;" method="post" class="form-inline" id="form">
<input type="text" id="message" class="input-medium" placeholder="Message" value="Hello, world!" />
<button type="button" class="btn" data-action="insert">Show</button>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
JavaScript的
var onloading = (function () {
$('body').on('click', ':button', function () {
var a = document.getElementById("message").value;
var hasS = new RegExp("^[s\s]+$").test(a);
alert(hasS);
});
}());
Run Code Online (Sandbox Code Playgroud)
示例http://jsfiddle.net/kXLv5/40/
归档时间: |
|
查看次数: |
6953 次 |
最近记录: |