English 中文(简体)
对按空间/公用区分开的对口单位的登记
原标题:Regex for tags separated by spaces/commas, up to n tags
  • 时间:2011-11-20 23:17:34
  •  标签:
  • php
  • regex

我愿通过在《法典》认证图书馆中定期表达的方式,验证用户对职位标记索引的投入。

理想的情况是,监管机构有以下条件:

  1. allow only letters and numbers
  2. tags will be considered unique entities if separated by space (any number) or comma (any number)
  3. there should be a limit to the number of tags (for ex in this case 6)

这里有一些部分解决办法:

但是,他们并没有完全解决我的问题。

任何建议?

最佳回答

如果大家想要证明是正当的,那么这应当做到:

^[a-zA-Z0-9]+(?:[ ,]+[a-zA-Z0-9]+){0,5}$

Same regex,但附有评论和白色空间:

^ #beginning of string
[a-zA-Z0-9]+ #any sequence of alphanumeric letters
(?: #start of non capturing group
    [ ,]+ #between 1 and int delimiting chars
    [a-zA-Z0-9]+ #again, any sequence of alphanumeric letters
) #end of non capturing group
{0,5} #allow between 0 and n-1 occurrences of preceding group
$ #end of string

允许对主要/交易空间/公用场所/公用场所进行投入。

^[ ,]*[a-zA-Z0-9]+(?:[ ,]+[a-zA-Z0-9]+){0,5}[ ,]*$

并且为了进一步允许零对口单位的投入,可以修改:

^[ ,]*(?:[a-zA-Z0-9]+(?:[ ,]+[a-zA-Z0-9]+){0,5})?[ ,]*$
问题回答

《刑法》规定:

^w+[,s]w+[,s]w+[,s]w+[,s]w+[,s]w+$




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签