2016-09-20 2 views
0

JavaScriptでIsNan関数を使用すると正しい結果を得ることができません NUBERを入力すると(EX 2342、1111 ...)IsNan関数の結果が真。 inNan関数は数字ではなく文字を認識すると思います。 どうすれば修正できますか?JavaScriptでIsNan関数を使用すると正しい結果を得ることができません

<%@ 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> 
+0

'number.isNan' =>'ますisNaN(数) ' – noahnu

答えて

1

あなたは間違った方法でそれを使用しているこの

if(isNaN(updateno)){ 
       alert("YOU HAVE TO INPUT NUMBER VALUE"); 
} 
+0

:P – Sunny

+0

私は認識することができない私はあなたがやろうとしていると思う何

はこのようなものですそれisNanはタイプミスです!私はそのサニーのアドバイスに従って成功しようとする! JavaScriptのサポートvar型と多分私はisNaNが認識されることができると思うそれはパラメータ値が '番号'です。もちろんあなたのアドバイスも正しいです! – prepare123

0

を使用してください。 NaNには2つの大きなNがあることに注意してください。 Number.isNaNfunction on the Number object prototypeです。それを呼び出す正しい方法はisNaN(something)です。

updateno変数は文字列です。だから、isNaNを呼び出すことはできません。コーディング、prepare123 @ハッピー

// Attempt to convert the string into a number 
var updateno = parseInt($("#no").val().replace(/^\s+|\s+$/g, "")); 

if (!isNaN(updateno)) { 
    // it parsed as a number 
} else { 
    // it wasn't parseable to a number, parseInt returned `NaN` 
} 
+0

あなたのコメントは私にとって非常に便利です!私はisNanがタイプミスであることを認識できません!私はサニーが助言し成功することを試みる! – prepare123

関連する問題