SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast MeLoDi's Avatar
    Join Date
    Sep 2003
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question checking form field format function???

    hi there i have a form field which i need to validate. this feild can accept numbers as well as this format e.g 1-2 and 1,2,3,4,5
    how do i go about it?

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'd want something like this:

    HTML Code:
    <script type="text/javascript">
    function checkIt(elm)
    {
       if (elm.value.test(/^[0-9]+-[0-9]+$|^[0-9]+(,[0-9])*$/))
       {
          return true;
       }
        alert('Your field is wrong!!!?!?!');
        return false;
    }
    </script>
    
    <form onsubmit="return checkIt(yourField)" action="">
    <input name="yourField" type="text" value="blah" />
    </form>
    ck :: bringing chris to the masses.

  3. #3
    SitePoint Enthusiast MeLoDi's Avatar
    Join Date
    Sep 2003
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i havea validate function and i adde this bit of code but it doest seem to work?
    PHP Code:
    function DataValidation()
    {
    if (
    document.addform.block.value == "") {
    alert("You must enter a value for Block!");
    return 
    false;
    else 
    if (
    document.addform.block.value(/^[0-9]+-[0-9]+$|^[0-9]+(,[0-9])*$/)) {
     return 
    true
     } 
    alert('Your field is wrong!'); 
     return 
    false
     
    elm.focus();
    elm.select();
     } 
    }
    :
    :
    :

    how do i solve this?

  4. #4
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You forgot .test after .value
    ck :: bringing chris to the masses.


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
  •