I want to check if a string contain a digit in jsp .I know how to do this in java but don't know how to do this in jsp ? Can anyone help me?
firstNumber.matches("[0-9]{1,13}(\\.[0-9]*)?")
JSP is Java (more or less):
<% if (firstNumber.matches(".*[0-9].*")) {
// do something
%>
Why not use Expression Language constructs?
<c:set var="myValue">${firstNumber}</c:set>
<c:choose>
<c:when test="${myValue.matches('.*[0-9].*')}">
${var} contains number!
</c:when>
<c:otherwise>
<!--do something-->
</c:otherwise>
</c:choose>
尝试使用此检查:
<c:if test='${firstNumber.matches(".*[0-9].*")}'>
You can use a regex to find out if the String contains a number. Take a look at the matches() method
<%@ page import="java.util.regex.*" %>
<% if(firstNumber.matches(".*\\d.*")){
// contains a number
} %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.