当我在JavaScript中使用IsNan函数时,我无法获得正确的结果
当我输入NUBER时(EX 2342、1111 ...)IsNan函数结果为true。
我认为在Nan函数中识别字母不是数字。
我该如何解决?
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<c:url value='/resources/js/jquery-1.11.1.min.js'/>"></script>
<link rel="stylesheet" href="resources/css/style.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<title>Insert title here</title>
</head>
<script type="text/javascript">
$(document).ready(function(){
$("#insertbtn").on("click",function(){
var updateno =$("#no").val().replace(/^\s+|\s+$/g, "");
alert(updateno);
if(!updateno.isNan){
alert("YOU HAVE TO INPUT NUMBER VALUE");
}else if(updateno.length<5){
alert("YOU HAVE TO INPUT 5 CHARACTOR ");
}else {
$("#insertform").submit();
}
});
});
</script>
<body>
<div class="all">
<%@ include file="layout/header.jsp" %>
<div>
<%@ include file="layout/menu.jsp" %>
<form method="POST" action="memberinsert" id="insertform" >
<div class="main">
<c:if test="${not empty no}" >
<table>
<tr>
<th>NAME</th>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<th>EPLOYEENUMBER</th>
<td><input type="text" name="no" id="no"></td>
</tr>
<tr>
<th>パスワード</th>
<td><input type="text" name="password" id="password" ></td>
</tr>
<tr>
<td colspan="2" style="background: white;border-bottom: dotted red;" align="right">
<input type="button" id="insertbtn" value="SUBMIT" class="btn btn-default" >
<!-- <input type="button" id="canclebtn" onclick="location.href='memberlist'"> -->
</td>
</tr>
</table>
</c:if>
<c:if test="${empty no}" >
IF YOU WANT TO USE THIS SERVICE YOU HAVE TO NEED LOGIN
</c:if>
</div>
</form>
</div>
</div>
</body>
最佳答案
用这个
if(isNaN(updateno)){
alert("YOU HAVE TO INPUT NUMBER VALUE");
}