我可以在javascript中使用以下代码进行验证 [英] can i use the following code in javascript for validation

查看:58
本文介绍了我可以在javascript中使用以下代码进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在javascript中使用以下代码进行验证:

第一个用于名称验证,该名称不应包含任何数字,第二个代码用于电话号码验证,其中数字应仅启动97,98

can i use the following code in javascript for validation:
The first one is for Name validation that name should not contain any numerals and second code is for phone number validation in which number should only starts with 97,98

function name()
       {
           var a;
           a = document.form1.TextBox1.value;
           for (i = 0; i < a.length; i++)
           {
               if (a.indexof(charCodeAt(i) > 48) != -1 && a.indexof(charCodeAt(i) < 58) != -1)
                {
                   alert("please enter valid name");
               }

           }
       }
       function phno()
       {
       var b;
       b = document.form1.TextBox4.value;
       if (b.charAt(0) == 57 && b.charAt(1) == 56)
       {
       alert("This number is acceptable");
       }
       else if (b.charAt(0) == 57 && b.charAt(1) == 55)
       alert("this number is acceptable");

   }

推荐答案

代码中存在一些问题。



我修改了它以排除 indexof 函数并更改了 charAt charCodeAt in phno()



And是的,函数名不能是name(),所以我已经改为nameValidation()



演示 - [演示] javaScript验证名称和电话号码问题 [ ^ ]。



检查它是如何工作的。
There are some problems in the code.

I have modified it to exclude the indexof function and changed the charAt to charCodeAt in phno().

And yes, function name can't be "name()", so I have changed to "nameValidation()".

Demo - [Demo] javaScript Validation for name and phone number issue[^].

Check how it is working.


这篇关于我可以在javascript中使用以下代码进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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