0

This could well be a duplicate of an existing question. Can anyone recommend a Javascript or Jquery form validation script which offers the following.

  1. Error text can be positioned anywhere on the page rather than just alongside or underneath the field.
  2. Error message text should be in the page itself rather than buried in a separate js file - as the page will be available in several languages.
  3. The script needs to check for required fields and for valid email addresses. (I imagine this is pretty standard)

Normally I'd just use the validation controls which come with asp.net, but in this case I'm not using .net

Cheers

Edit - html here. And yes, we're trying to add a new skin to an old site!

<form method="post">
<table>
<tr>
    <td class="td-right" valign="top">Name:</td>
    <td><input style="width:400px"  type="text" name="name" /></td>
</tr>
<tr>
    <td class="td-right" valign="top">Telefon:</td>
    <td><input style="width:400px"  type="text" name="telephone" /></td>
</tr>
<tr>
    <td class="td-right" valign="top">Email-Adresse:</td>
    <td><input style="width:400px"  type="text" name="from" /></td>
</tr>
<tr>
    <td class="td-right" valign="top">Thema:</td>
    <td><input style="width:400px"  type="text" name="subject" /></td>
</tr>
<tr>
    <td class="td-right" valign="top">Nachricht:</td>
    <td><textarea style="width:400px; height:200px"  name="message"></textarea></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td><input class="button" type="submit" name="submit" value="senden" /></td>
</tr>
</table>
</form>
3
  • If you're using HTML5 you could use the attributes required and for the email the email-type input field, then you could use simple javascript to check if its valid or not. Do you have any html? btw. here is a good link to this: html5rocks.com/en/tutorials/forms/constraintvalidation Commented Jan 6, 2014 at 11:54
  • @ Agash Thamo XHTML 1.0 trans I'm afraid. I've added HTML to the question Commented Jan 6, 2014 at 12:10
  • Well since you can't use data-attributes and so on, it will be difficult to find a good form-validation lib. I still think it's the best if you just make the simple tests with plain javascript since it's not that much to validate. Commented Jan 6, 2014 at 12:22

1 Answer 1

1

Look the example....

 $("#f_valid").validate(
  {
      rules:
      {
          firstname:"required",
          address:"required",
          pin:
          {
              required:true,
              digits:true,
              minlength:6,
          },
           gender:"required",
           dob:
           {
              required:true,
              dateISO:true,
           },
           statename:"required",

           mobile:
           {
               required:true,
               digits:true,
               rangelength: [10, 12]
           },
          email:
          {
               required:true,
               email:true,
          },
          password:
          {
             required:true,
             minlength:6,
          },
          confirmpassword:
          {
            required:true,
            equalTo:'#pass'
          },
           keyskills:"required",
           course_done:"required",
           university:"required",
           yearof passing:
           {
             required:true,
             digits:true,
           },
            mark1:
            {
              required:true,
              digits:true,
            },

            photo:
            {
                required:true,
                extension:'jpg|png|gif',
            },
            resume:
            {
               required:true,
               extension:'txt|doc|docx|pdf',
            },
      },
      errorPlacement:function(error, element)
    {
        if($(element).attr("name")=="gender")
        {
            $(element).parent().append(error);
        }else
        {
        $(error).insertAfter(element);
        }   
    },

  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.