验证asp.net中的文本框 [英] validating textbox in asp.net
本文介绍了验证asp.net中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个示例asp.net应用程序,我需要验证一个文本框,我使用JavaScript来检查该文本框是否为空.但是,如果我仅输入空格,它将绕过验证.如何克服它. ........
am developping an sample asp.net application i need to validate a textbox i used javascript to check whether the text box is empty or not.but its byepassing the validation if i enter a space only.how can i overcome it..........
推荐答案
如果您还想计算空格,请检查文本框文本的长度.您可以尝试以下javascript代码:
If you want to count empty spaces also, check the length of the textbox''s text. You can try below javascript code:
document.getElementById("txt").value.length
您也可以尝试JQuery:
You can also try JQuery:
("#txt").val().length
("#txt").val().length
如果您不想考虑空格,则需要在检查长度之前修剪文本.要在javascript中修剪文本,您可以使用solution#2,对于JQuery,您可以这样操作:
If you don''t want to consider spaces then you need to trim the text before checking for length. To trim text in javascript you can use solution#2 and for JQuery you can do it like this:
.trim(
这篇关于验证asp.net中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文