如何使用JavaScript验证asp.net中的文本框. [英] how to validate a textbox in asp.net using javascript.

查看:48
本文介绍了如何使用JavaScript验证asp.net中的文本框.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要使用javascript验证asp.net中的3个文本框即可.我需要检查文本框是否为null或文本框是否具有任何整数值.单击保存按钮时完成.为此,我首先添加了一个javascript文件....我不知道编码部分,任何人都可以帮助我............

i just need to validate 3 textboxes in asp.net using javascript.i need to check whether textbox is null or textbox is having any integer values.if so it must give an alert saying only alphabets are allowed...this should be done when one save button is clicked.for doing i jst added one javascript file....i dont know the coding part,,,can anyonw plss help me............

推荐答案

Pl检查以下链接,例如:

http://www.c-sharpcorner.com/UploadFile/purankaushal/103222006013805AM/1.aspx [ ^ ]
自验证ASP.NET文本框 [ http://msdn.microsoft.com/en-us/library/aa479013.aspx [ ^ ]
Pl check the following link for example:

http://www.c-sharpcorner.com/UploadFile/purankaushal/103222006013805AM/1.aspx[^]
Self Validating ASP.NET Text Box[^]
http://msdn.microsoft.com/en-us/library/aa479013.aspx[^]


您好,仅用于验证,您可以输入字母数字,然后

在文本框上添加属性
Hi, for validate only you can enter alpha numeric then

add attribute on textbox
txtBox.attributes.add("onkeypress", "javascript:return isAlphaNumeric(event);");



JS函数



JS function

function isAlphaNumeric(e)
 {
//    alert(e.which);
    if ((e.which < 48 || e.which > 57))
    {
        if ((e.which < 123 && e.which > 96))
        {
            return true;
        }
        if ((e.which < 91 && e.which > 64))
        {
            return true;
        }
        if (e.which == 8 || e.which == 0 || e.which == 32)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}


这篇关于如何使用JavaScript验证asp.net中的文本框.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆