如何检查String是否包含数字?

时间:2015-12-15 07:12:54

标签: java jsp

我想检查字符串是否包含jsp中的数字。我知道如何在java中执行此操作但不知道如何在jsp中执行此操作? 任何人都可以帮助我吗?

firstNumber.matches("[0-9]{1,13}(\\.[0-9]*)?")

4 个答案:

答案 0 :(得分:2)

JSP Java(或多或少):

<% if (firstNumber.matches(".*[0-9].*")) {
       // do something
%>

答案 1 :(得分:0)

为什么不使用表达式语言结构?

   <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>

答案 2 :(得分:0)

尝试使用它来检查:

<Directory /var/www/public_html/current_directory/image>
    Require all granted
</Directory>

答案 3 :(得分:0)

您可以使用正则表达式来查明字符串是否包含数字。看一下matches()方法

function paginate() {
// consider adding an id to your table,
// just incase a second table ever enters the picture..?
var items = jQuery("#searched_prfiles .row .col-md-4");

var numItems = items.length;
var perPage = 2;

var pagination_placeholder_selector = "#pagination_links"; // put in a variable to ensure proper changes in the future
var myPageName = "#page-"; // a number will follow for each page

// only show the first 2 (or "first per_page") items initially
items.slice(perPage).hide();

// now setup your pagination
// you need that .pagination-page div before/after your table
jQuery(pagination_placeholder_selector).pagination({
    items: numItems,
    itemsOnPage: perPage,
    cssStyle: "light-theme",
    hrefTextPrefix: myPageName,
    onPageClick: function(pageNumber) { // this is where the magic happens
        // someone changed page, lets hide/show trs appropriately
        var showFrom = perPage * (pageNumber - 1);
        var showTo = showFrom + perPage;

        items.hide() // first hide everything, then show for the new page
             .slice(showFrom, showTo).show();
    }
});



// EDIT: extra stuff to cover url fragments (i.e. #page-3)
// https://github.com/bilalakil/bin/tree/master/simplepagination/page-fragment
// is more thoroughly commented (to explain the regular expression)

// we'll create a function to check the url fragment and change page
// we're storing this function in a variable so we can reuse it
var checkFragment = function() {
    // if there's no hash, make sure we go to page 1
    var hash = window.location.hash || (myPageName+"1");

    // we'll use regex to check the hash string
    var re = new RegExp("^"+myPageName+"(\\d+)$");
    hash = hash.match(re);

    if(hash)
        // the selectPage function is described in the documentation
        // we've captured the page number in a regex group: (\d+)
        jQuery(pagination_placeholder_selector).pagination("selectPage", parseInt(hash[1]));
};

// we'll call this function whenever the back/forward is pressed
jQuery(window).bind("popstate", checkFragment);

// and we'll also call it to check right now!
checkFragment();