homeservicesportfoliocontactwebsite design tutorials
 

 

 
 

To the index

Regular Expressions

  • How can I prevent users entering £ $ and , in a currency form field?
  • How can I strip HTML from a variable?
  • What are Regular Expressions?
  • How can I check that only numbers and letters have been entered into a form field?
  • What is the Regular Expression to validate an e-mail address?
  • Where can I find out more about Regular Expressions?
  • Beginner

    How can I prevent users entering £ $ and , in a currency form field?

    Use this regular expression

    REReplace(YourCurrencyField, "[^0-9\.]+", "", "ALL")

    That will delete everything but decimals and numbers.

    to question

    How can I strip HTML from a variable?

    <cfset Field = ReReplace(Field, "<[^>]*>", "", "all")>

    to question

    What are Regular Expressions?

    Taken from Ben Forta's Advanced Web Application Construction Kit

    Regular Expressions are a quasi-language etc etc (!!!copy from chapter intro!!!)

    to question

    Advanced

    How can I check that only numbers and letters have been entered into a form field?

    This RE will match if anything but a letter or number is passed.

    <cfif REFind("[^a-zA-Z0-9]", YourStringVariable)>

    to question

    What is the Regular Expression to validate an e-mail address?

    A special thanks to Erik Voldengen for this e-mail validation RegEx. It handles multiple top levels, checks for valid root domains, disallows double @@ and will ensure that the email address contains just "alphanumeric" characters.

    <cfset Email = "jon.doe@TopLevel.YourSite.com">
    
    <cfif REFindNocase("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$", Email)>
       Good address.
    <cfelse>
       Very, very bad.
    </cfif>

    to question

    Where can I find out more about Regular Expressions?

    http://www.houseoffusion.com/httpagent.ppt
    http://www.cfcomet.com/cfcomet/other/index.cfm?ArticleID=F0A14065-EF7A-4A9E-AED5F28EF8C19D65

    Also, consult the ColdFusion Studio help files. Check under Using ColdFusion Studio | 12 Testing and Maintaining Web Pages | Using Find and Replace.

    to question