高分征求正则表达式一个

验正字符串的格式为"1,4,3,6"或单独一个"3"里面不数字不能重复

---------------------------------------------------------------

能不能换一种说法?不是很明白你的意思
---------------------------------------------------------------

xizi2002 (戏子) 你在不在?莫非这200分注定不属于我?
---------------------------------------------------------------

$str='33';
if(ereg('^(1,3,4,6)$ ¦^(3){1}$',$str))
die('same');
else
die('no');
---------------------------------------------------------------

不好意思。我以为你不在,错误的理解了你的意思
---------------------------------------------------------------

惭愧,做不出来
---------------------------------------------------------------

$str="1,3,3,4,4";
//$str="3";
//$str="1,2,3";
if(preg_match("/^\d(,\d)*$/",$str)&&array_unique($arr=explode(',',$str))==$arr){
echo "匹配";
}else{
echo "不匹配";
}
---------------------------------------------------------------

上面:*=>{0,9}

php:
$str="1,3,3,4,4";
//$str="3";
//$str="1,2,3";
if(preg_match("/^\d(,\d){0,9}$/",$str)&&array_unique($arr=explode(',',$str))==$arr){
echo "匹配";
}else{
echo "不匹配";
}

Js:

 1<script>   
 2var str="1,3,3,4";   
 3function check(str){   
 4if(/^\d(,\d){0,9}$/.test(str)){   
 5var str1=str.replace(/,/g,"");   
 6for(var n=0;n<str1.length;n++)   
 7if(str1.lastIndexOf(str1.substr(n,1))!=n) return false;   
 8return true;   
 9}   
10return false;   
11}   
12alert(check(str));   
13</script>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus