Is it possible to do form validation on the client and server only with JavaScript?

-1

In the particular case, I would like to create a form for contact, with name, type of service (dropdown menu: webdesign, mobile), subject and message. I would also like to send this form with name, type of service and message to a specific email in text format.

Usually the validation of a form is done on the server with ASP, Java. Now, would it be possible to validate with JavaScript only? What technology is required to do this?

    
asked by anonymous 19.06.2016 / 12:33

1 answer

4

You can use Client-Side validation with Javascript (pure or using some library like JQuery, AngularJS, etc.). This will occur before you send the data to the server. Something like this:

function Valida() {
    if (document.getElementById("nome").value.length < 1) {
        alert("Digite um nome.");
        document.getElementById("nome").focus();
        return false;
    } else if (document.getElementById("idade").value.length < 1) {
        alert("Digite uma idade.");
        document.getElementById("idade").focus();
        return false;
    } else if (document.getElementById("sexo").value == 0) {
        alert("Escolha um sexo.");
        document.getElementById("sexo").focus();
        return false;
    } else {
        return true;
    }
}

Source: link

You can (and recommend) do the validation also on the server side using NodeJS and Javascript.

The code is great, check out link .

You can send txt or html emails using nodemailer, plugin for express:

var nodemailer = require('nodemailer');

// create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport('smtps://user%40gmail.com:[email protected]');

// setup e-mail data with unicode symbols
var mailOptions = {
    from: '"Fred Foo                                     
19.06.2016 / 22:32