\b is an escape sequence that, as taken from the docs:

"Specifies a boundary defined by a transition from an alphanumeric character
to a nonalphanumeric character, or from a nonalphanumeric character to an
alphanumeric character."

Since you're passing in "Dr|", the pipe character matches, as it is a
transition from an alphanumeric character to a non-alphanumeric character.

Assuming that you're wanting the title to be the only thing in the field,
with the exception of a possible period at the end, try something like this:

<cfset var titleRegEx = "\A(Dr|Prof|Mr|Mrs|Ms|Miss)(\.)?\Z" />



On Wed, Oct 15, 2008 at 1:38 PM, Richard White wrote:

> Hi,
>
> i have a function that simply tries to match a value that is being passed
> in matches a title. the function is currently as follows:
>
> <cffunction name="isValidTitle" hint="is passed a value, and checks to
> ensure that it is either M or F, and either returns true or the error">
>  <cfargument name="value" type="any" required="true">
>
>  <!--- declare the regaulr expression set --->
>  <cfset var titleRegEx = "\b(Dr|Prof|Mr|Mrs|Ms|Miss)\b"> <!--- allowable
> --->
>  <cfset var regExMatchArray = rematchnocase(titleRegEx,value)>
>
>  <!--- looks through the string to find m or f, if everything is ok then it
> returns a number 1 greater than the length of the value, else it returns the
> position of the character in the value that it fails on --->
>  <cfif arraylen(regExMatchArray) eq 0 or len(regExMatchArray[1]) neq
> len(value)>
>    <cfreturn "Invalid Title: #value# (Valid Title:
> Dr,Prof,Mr,Mrs,Ms,Miss)">
>  <cfelse>
>    <cfreturn true>
>  </cfif>
>
> </cffunction>
>
> i have been looking at various regex tutorials about options, and also
> looked the the very useful regex tutorial site:
> http://www.regular-expressions.info/alternation.html
>
> but the problem i am having is that it will match any pattern including the
> pipe, so if i type in Dr| then it will return true. however i want it to
> return false, i cannot seem to find anywhere that tells me how to deal with
> this
>
> i would appreciate any feedback
>
> thanks
>
> richard
>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:313953
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to