0

Is it possible to validate a form without Javascript? Rest of my website is written in c# and asp.net and the server hosting my website doesn't allow Javascript. Is there any other ways to validate a form without this? Thanks!

function validateForm()
{
var x=document.forms["myForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
   alert("Not a valid e-mail address");
   return false;
  }
}
3
  • 1
    Well i know, that's not an answer. But if hoster does not allow javascript... run away from him Commented Apr 8, 2014 at 6:14
  • Why would the server care if you run JavaScript on remote unrelated machines? Commented Apr 8, 2014 at 6:15
  • If it "doesn't allow javascript" you can't run half of your C# codes because even they are using javascript Commented Apr 8, 2014 at 6:17

2 Answers 2

1

Yes, you can let the browser validate it partially.

To do this, you can use the pattern attribute, required, etc.

Further Reading.

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

Comments

0

For built in email validation set up input type to email:

   <input type="email" name="email">

If it's required add another attribute:

   <input type="email" name="email" required>

But remember, that it's only client side validation and supported by not all browsers, so you must check input on server as well

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.