Jump to content

60 second basic problem -.-


stupot2212

Recommended Posts

I know how simple this must be

But I have spent almost 5 hours now -.-

 

If it makes any difference, its for use within WHMCS custom fields validation..

 

 

All that I want, is to use a regular expression to check that my input field is :

A single word - no spaces and only lower case A to Z letters.. no spaces, no -'s no nothing

 

I am either really stupid or too tired.

Would appreciate any help very much

 

:-[

Link to comment
Share on other sites

The # are delimiters, they delimit (mark the start and end points of) the regular expression contained within.  They are required because in the PCRE family of functions (preg_*) the regular expression is combined with some (optional) modifiers which affect the behaviour of the expression. The delimiters, regular expression and modifiers combined are called a pattern.

 

Given the pattern /hello/i then the parts are:

  • Delimiter is /
  • Regular expression is hello
  • Modifier is i (makes the expression match case-insensitively)

 

The delimiters are most commonly one of /, ~, # or @. Far more characters are allowed as delimiters but it is not important at this stage to know precisely which ones.

 

The D modifier in cags' pattern affects the behaviour of the $ character in the regular expression. Normally (i.e., without the D modifier; lets ignore multiline mode and character classes for now) the $ matches the point right at the end of the subject string, or immediately before a newline at the end of the subject string if there is one.

 

To give an example: /def$/ matches the string "abcdef" and also "abcdef\n".  When the D modifier is used, the second example (with a trailing newline) will not be matched.  It is often used just to be that extra little bit sure that the subject string does not contain a trailing newline. An alternative, not wanting to confuse you, is to use the \z escape sequence which will only ever match at the very end of the subject string: /def\z/ will match "abcdef" but not "abcdef\n"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.