验证名称飞行

时间:2018-01-31 15:37:14

标签: javascript



String first = (rs1.getString("PROP_VALUE"));   
String second = (rs1.getString("VEN_ITEM"));

String url = (first+second);

URL obj = new URL(url);

HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

int  responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " +url);
System.out.println("Response Code : " + responseCode);


BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    content.append(inputLine);
    }
    in.close();
    con.disconnect(); 




此代码通过限制特殊字符和空格来验证名称字段。但我需要在全名之间输入一个空格。

2 个答案:

答案 0 :(得分:0)

您只需将32找到if() space的空间的密钥代码添加到代码段中的<html> <body> <form method="POST" action=""/> </br> <label>Name</label> <input type="text" name="name" required onkeypress="javascript:return checkNum(event)"/> </br></br> <input type="submit" value="submit"/> </form> </body> <script> function checkNum() { if ((event.keyCode > 64 ) || (event.keyCode > 96 && event.keyCode < 123) || event.keyCode == 8 || event.keyCode == 32) //Added event.keyCode == 32 to the conditionals return true; else { alert("Please enter only char"); return false; } } </script>即可。这将阻止该函数阻止输入

中的空格输入

要将它放在名字和姓氏之间,您必须在添加do.call("rbind", ...)

之前添加对输入字段长度的检查

L

希望这有帮助!

答案 1 :(得分:0)

我包含了char代码,允许空间为32以及退格,删除和你自己的a-z,A-Z,1-9等......

checknum(event)
    {           
        var val = event.charCode;
       return((val > 64 && val < 91) || (val > 96 && val < 123) || val == 8 || val == 32 || (val >= 48 && val <= 57)); 
    }