检查字符串是否包含数字或数字-Thymeleaf [英] Check if a string contains number or is numeric - Thymeleaf

查看:834
本文介绍了检查字符串是否包含数字或数字-Thymeleaf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以检查字符串是否为数字. {#strings.isNumeric(dataField)}不起作用.

Is there a way to check if string is numeric. {#strings.isNumeric(dataField)} doesn't work.

如何检查字符串是否包含数字(以及特定的数字位数)-是否可以使用RegEx或可以调用的内置函数?

How can I check if string contains numbers (specific number of digits as well) - is there a RegEx that can be used, or an inbuilt function that can be called?

想在下面避免这种情况:

Want to avoid this below:

{#string.contains('1') or #string.contains('2')}

推荐答案

尝试matches():

{#dataField.matches('[0-9]{3,8}')}

这将匹配一个3到8位数字(包括3个数字)的字符串.您可以将这些值更改为适合您的值.

This matches a string that is from 3 to 8 digits long (inclusive). You can change those values to whatever works for you.

您还可以使用开放式长度范围:[0-9]{3,}表示至少3位数字"

You can also use open-ended length ranges: [0-9]{3,} means "at least 3 digits"

这篇关于检查字符串是否包含数字或数字-Thymeleaf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆