正则表达式用于数字比较? [英] Regex for number comparison?

查看:119
本文介绍了正则表达式用于数字比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果数据库中输入匹配数据的输入5位数字,我想执行regex返回true/false,无需满足序列号,但需要确切的数字.

I would like to perform regex to return true/false if the input 5 digit from input matching data in database, no need to cater of the sequence, but need the exact numbers.

例如:在数据库中,我有12345

Eg: In database I have 12345

当我键入5位数的值进行搜索时,我想确定它是否与12345中的每个数字都匹配.

When I key in a 5 digit value into search, I want to find out whether it is matching the each number inside the 12345.

如果我键入34152,它应该返回true

If I key in 34152- it should return true

如果我键入14325,它应该返回true

If I key in 14325- it should return true

如果我键入65432,它应该返回false

If I key in 65432- it should return false

如果我键入11234,它应该返回false

If I key in 11234- it should return false

例如:在数据库中,我有44512

Eg: In database I have 44512

如果我键入21454,它应该返回true

If I key in 21454- it should return true

如果我键入21455,它应该返回false

If I key in 21455- it should return false

如何在正则表达式中使用php

How to do this using php with regex

推荐答案

这是一种避免使用正则表达式的方法

This is a way avoiding regex

<?php
function cmpkey($a,$b){
  $aa =  str_split($a); sort($aa);
  $bb =  str_split($b); sort($bb);
  return ( implode("",$aa) == implode("",$bb));
}
?>

这篇关于正则表达式用于数字比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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