SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Mar 2002
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inserting Special Characters

    I have a drop down combo that has a list of predefined regular expressions. When a user selects one, I'd like the regular expression to appear in a textbox. Everything works fine unless there is a brace {}, which seems to disappear and break the code. Does anyone know how I could insert a regular expression with braces?

    Thanks for your help.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hard to say what 'break[s] the code' without - seeing the code.
    ::: certified wild guess :::

  3. #3
    SitePoint Member
    Join Date
    Mar 2002
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the drop down box. I've only put in a few so far. When I load the page, the braces and the number in the braces doesn't appear.

    <select name="selValid">
    <option>Preset Restriction</option>
    <option value="[0-9]">Numbers Only</option>
    <option value="[a-zA-Z]">Alpha Only</option>
    <option value="[a-z]">Alpha Lowercase</option>
    <option value="[A-Z]">Alpha Uppercase</option>
    <option value="[a-zA-Z0-9]">Alphanumeric</option>
    <option value="email">Email</option>
    <option value="[0-9]{5}">Zip</option>
    <option value="([0-9]{5})-([0-9]{4})">Zip+4</option>
    <option value="phone">Phone</option>
    <option value="date">Date (mm/dd/yyyy)</option>
    </select>

    There's a button that calls a javascript function when clicked:

    function addValid(valid)
    {
    document.frmSL_Text.txtRestrict.value = valid;
    }

    It will add the text to the textbox, but not the braces because those disappear when the page loads.

    Thanks for your help.

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works for me...

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
    	"http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript" language="javascript">
     
    function addValid(valid)
    {
    document.frmSL_Text.txtRestrict.value = valid;
    }
     
    </script>
    </head>
    <body>
    <form name="frmSL_Text">
    <select name="selValid" style="font:14px verdana;">
    <option>Preset Restriction</option>
    <option value="[0-9]">Numbers Only</option>
    <option value="[a-zA-Z]">Alpha Only</option>
    <option value="[a-z]">Alpha Lowercase</option>
    <option value="[A-Z]">Alpha Uppercase</option>
    <option value="[a-zA-Z0-9]">Alphanumeric</option>
    <option value="email">Email</option>
    <option value="[0-9]{5}">Zip</option>
    <option value="([0-9]{5})-([0-9]{4})">Zip+4</option>
    <option value="phone">Phone</option>
    <option value="date">Date (mm/dd/yyyy)</option>
    </select>
    <input type="text" name="txtRestrict" style="width:190px;font:bold 14px verdana;">
    <input type="button" value="Transfer" style="font:14px verdana;" 
    onclick="addValid(selValid.options[selValid.selectedIndex].value)">
    </form>
    </body>
    </html>
    ::: certified wild guess :::

  5. #5
    SitePoint Member
    Join Date
    Mar 2002
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh boy I feel silly. It turns out that the braces would disappear because of the templating system that I'm using. Thanks for your help, I'm sorry for my stupid question.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •