name attribute values must be unique within a form, but can be repeated in another form on the same page. class attribute values can be repeated as many times as you wish.
Also, it is a requirement that the <form> element and all input fields within a form must have a name attribute value.
Why not use the free jQuery Validation plugin? It will do what you wish and give you tons more validation options too for free!
Here is a taster of how to use it...
HTML markup, with validation requirements added...
<form action="#" method="post" name="first-form">
<input type="text" name="name" required minlength="2" maxlength="30" pattern="^[a-zA-Z\s]+$" placeholder="Name" title="Name is required, and must contain between 2 and 30 alpha characters" />