Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    validate text field

    Hi all. I have the below function to validate a text field. On one page this charge account field is duplicated for several rows and is named "charge[]". How can I alter the below function to validate each row if each field is named the same.?

    //VALIDATE CHARGE
    if(theForm.charge){
    if(!theForm.charge.value.match( /(^\d{5}$)|(^\d{6}$)|(^\d{6}-\d{6}$)/) ){
    alert("Please input a valid Charge Account!")
    theForm.charge.style.backgroundColor='pink';
    theForm.charge.focus();
    return false
    }}

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,302
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    Tracy -

    You often ask for assistance in this forum, but as far as I can see you never offer any thanks to people who assist you. Your statistics show 224 posts but 0 thanks given. In fact you were provided with this regex only the other day.

    I was just wondering if there is any particular reason why you do not trouble to thank those who assist you, but just make like Oliver Twist - "Please sir, I want some more".

  • #3
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by nikko50 View Post
    How can I alter the below function to validate each row if each field is named the same?
    Test the element for the presence of a .length property. If it has one, loop through the elements. Arrange it so that it only alerts once even if multiple fields fail, ideally without using a break statement.


  •  

    Posting Permissions

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