javascript验证文本框中键入的字符串前面的间距 [英] javascript validation for spacing in front of a string typed in the textbox
本文介绍了javascript验证文本框中键入的字符串前面的间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过javascript设置验证文本框中键入的字符串前面的间距。
解决方案
查看此文章
< a href =http://www.codeproject.com/Questions/414372/Java-Script-validation-for-not-allowing-Spaces> Java脚本验证不允许使用空格。 [ ^ ]
如果您的目的是仅验证前导空格,请尝试使用Javascript中的indexOf方法
下面的内容
function CheckLeadingSpace()
{
var txt = document.getElementById (' txtBoxID');
var n = txt。 value .indexOf( , 0 ); / / 检查位置1的空间
如果(n == 0 ){
alert( InValid跨度>);
return false ;
}
返回 true ;
}
在TextBox onblur或keyup event <上尝试 this / span>等等
希望此帮助......
How to set validation via javascript for spacing in front of a string typed in the textbox.
解决方案
check this article
Java Script validation for not allowing Spaces.[^]
If your intention is to validate only the leading space try the indexOf method in Javascript
Something like below
function CheckLeadingSpace() { var txt= document.getElementById('txtBoxID'); var n=txt.value.indexOf(" ",0);//Checks the space in position 1 if (n == 0) { alert("InValid"); return false; } return true; } Try this on TextBox onblur or keyup event etc. Hope this helps...
这篇关于javascript验证文本框中键入的字符串前面的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文