English 中文(简体)
核对重复空间特性
原标题:Regex to check for duplicate space characters

I have a requirement to write a regex to validate a text entry. The text must be between 5 and 16 characters (a-Z plus hyphen, underscore and space). This is fine but it must also check that there are not any consecutive spaces.

e.g.

hello        // PASS
hello there  // PASS
hi there you // PASS
hello  there // FAIL - two spaces between hello and there
最佳回答

你们可以使用这样的东西:

/^(?!.*  )[-a-z_ ]{5,16}z/i
问题回答

Java 我会同意我的看法。

"  |[^\p{L}_ -]"

(" isn t part of the regex). If the string matches this regex then it fails. I would check the size separately in an if sentence (faster that way).

如果没有统法协会的特性,如果你想用某种语言这样做:

ss|[^A-Za-z_ -]

Regex:

^([w-_]+([s]{0,1})[w-_]+)$

匹配

hello
hello there
hi there
he-llo
he_las test

http://www.ohchr.org。

hello  there
hello     there




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签