function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vandana Rattan 4Vandana Rattan 4 

Validate HTML Input elements

I have a Visualforce page containing HTML elements like:
 
<label for="firstName">First Name<span style="color: red;">*</span></label></b>
            <br></br>
            <input type="text" name="fName" id="fName"> </input>
            
			 
        	 <br></br>
			<b><label for="lastName">Last Name<span style="color: red;">*</span></label></b>
            <br></br>
            <input type="text" name="lName" for="lName" id="lName" > </input>

How can I validate these fields before submitting the form? The validations have to be for

Mandatory fields
Email format

Thanks in Advance
Best Answer chosen by Vandana Rattan 4
KaranrajKaranraj
Vandana -

Below is the HTML code for the required input validation, you have to set required = True
<input type="text" name="name" required="true"> </input>
You can set the Type="email" to set the input field to support values in email formate. Make sure that you have  set docType="Html-5.0"  in the apex:page attribute

All Answers

KaranrajKaranraj
Vandana -

Below is the HTML code for the required input validation, you have to set required = True
<input type="text" name="name" required="true"> </input>
You can set the Type="email" to set the input field to support values in email formate. Make sure that you have  set docType="Html-5.0"  in the apex:page attribute
This was selected as the best answer
Vandana Rattan 4Vandana Rattan 4
Thanks Karan,

For me strangely this was not working. I had checked this in first place. I had to write custome javascript code for validations.

Regards,
Vandana