[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Javascript regex, timer and string-split

Posted on 2009-12-16
4
Medium Priority
?
494 Views
Last Modified: 2013-11-19
I need the following functionality:

-User enters a string in a textbox
-If the string matches an integer, followed by ; and then follwed by a date - then after one second split the string into integer/date and put into two separate textboxes.

Is that hard...?

(you can run index.html directly in your browser)



[index.html]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
    <title>advanced js...</title>
    <style type="text/css">
        p{
            font-style: italic;
            font-size: large;
            
        }
    </style>
    <script type="text/javascript">
        function clrAll(){
            document.getElementById("input").value="";
            document.getElementById("number").value="";
            document.getElementById("date").value="";
        }
    </script>
</head>

<body bgcolor="whitesmoke">
    
    Please enter 666;2012-12-31 :<br/>
    <input type="text" id="input" size="40"/>
    
    <p>After one second, split input into these boxes if input matches integer;date ...:</p>
    
    
    Integer goes here:<br/>
    <input type="text" id="number" size="20"/>
    <br /><br />
    Date goes here:<br/>
    <input type="text" id="date" size="20"/>


    <br />
    <button onclick='clrAll()'>Clear</button>

</body>

</html>

Open in new window

ee.png
index.html
0
Comment
Question by:davidsperling
  • 2
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
HonorGod earned 2000 total points
ID: 26068413
sounds kind of like homework..
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
    <title>advanced js...</title>
    <style type="text/css">
        p{
            font-style: italic;
            font-size: large;
        }
    </style>
    <script type="text/javascript">
        function clrAll(){
            document.getElementById("input").value="";
            document.getElementById("number").value="";
            document.getElementById("date").value="";
        }
        function check( val ) {
          if ( /^(\d+);(\d{4}-\d{1,2}-\d{1,2})$/.test( val ) ) {
            setTimeout( function() {
                          document.getElementById( "number" ).value = RegExp.$1;
                          document.getElementById( "date"   ).value = RegExp.$2;
                        }, 1000
                      );
          }
        }
    </script>
</head>

<body bgcolor="whitesmoke">
    Please enter 666;2012-12-31 :<br/>
    <input type="text" id="input" size="40" onkeyup='check(this.value)'/>

    <p>After one second, split input into these boxes if input matches integer;date ...:</p>

    Integer goes here:<br/>
    <input type="text" id="number" size="20"/>
    <br /><br />
    Date goes here:<br/>
    <input type="text" id="date" size="20"/>

    <br />
    <button onclick='clrAll()'>Clear</button>
</body>

</html>

Open in new window

0
 
LVL 4

Author Comment

by:davidsperling
ID: 26069791
Don't worry, you're not helping me cheating with homework. It's a real world project ;-)
It's just that my js kung-fu is a bit rusty.
0
 
LVL 4

Author Closing Comment

by:davidsperling
ID: 31667015
Yes!
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 26071241
Thanks for the grade & points.

Good luck & have a Merry Christmas.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question