Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:53:38+00:00 2026-06-07T04:53:38+00:00

I have a control that is a date picker with validation using HTML5’s pattern

  • 0

I have a control that is a date picker with validation using HTML5’s “pattern” attribute with a regular expression. It works fine.

<input type='text' class='date-pick' name='breakEndIE' size='8' placeholder='01-03-2011' style='max-width:100px' pattern='^(((0[1-9]|[12]\d|3[01])-(0[13578]|1[02])-                ((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)-(0[13456789]|1[012])-((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])-02-((19|[2-9]\d)\d{2}))|(29-02-((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$' readonly='readonly' required />

However when I put it inside a script using document.write() it stops working. (Pattern always thinks there is an error in the formatting of the date)

<script>
            var ifFFOCHR = false;
            if (navigator.appVersion.indexOf("MSIE") > -1) ifFFOCHR = false;
            else if (navigator.appVersion.indexOf("Chrome") > -1) ifFFOCHR = true;
            else if (navigator.appVersion.indexOf("Safari") > -1) ifFFOCHR = false;
            else ifFFOCHR = true;

            if (ifFFOCHR == true) 
                {
                    //FIREFOX/CHROME/OPERA CODE HERE
                    document.write("<input type='text' class='date-pick' name='breakEnd' size='8' placeholder='01-03-2011' style='max-width:100px' pattern='^(((0[1-9]|[12]\d|3[01])-(0[13578]|1[02])-((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)-(0[13456789]|1[012])-((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])-02-((19|[2-9]\d)\d{2}))|(29-02-((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$' required />");
                }
            else 
                {
                    //IE/SAFARI CODE HERE
                    document.write("<input type='text' class='date-pick' name='breakEndIE' size='8' placeholder='01-03-2011' style='max-width:100px' pattern='^(((0[1-9]|[12]\d|3[01])-(0[13578]|1[02])-                ((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)-(0[13456789]|1[012])-((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])-02-((19|[2-9]\d)\d{2}))|(29-02-((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$' readonly='readonly' required />");
                }
            </script>

I have no idea why this is happening. I have tried copying and pasting the into the document.write() many times. It works outside it, but not in it. I have tried getting a friend to do it.
We tried it inside another script and it worked fine, it is just inside this script that it breaks.

Please help.

FYI: The script is to make certain code display inside IE & Safari and different code display in Firefox, Opera, and Chrome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:53:39+00:00Added an answer on June 7, 2026 at 4:53 am

    One strong possibility is that you have escape characters e.g. \d in your regex string. Those are treated literal characters when the pattern attribute is added inline, but the \ are treated with a different meaning when placed in a javascript string.

    Because you have now wrapped that expression in a string, you likely need to escape the \ character, e.g. \\d.

    Try writing your string out to console.log or calling alert() so you can visualise how your string has been interpreted by JavaScript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know of an ASP.NET date picker control that works well with JAWS
I currently have a control that is being hidden on my server side using
I have two input dates taking from Date Picker control. I have selected start
I'm using a form that has date picker controls on it. When the form
I'm using a usoft date time picker control in a dialog box. I started
I have a control that look something like this: <asp:DetailsView ID=dvUsers runat=server DataSourceID=odsData DataKeyNames=Id>
I have a control that has a Filter property that expects a function that
I have a control that goes inactive under some conditions in my iPhone app.
I have a control that has a byte array in it. Every now and
I have a control that handles commenting. In this control, I have set a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.