Validation

dalton.lesko088

Baseband Member
Messages
55
Location
USA
I need to write an if statement to "validate" an input in a form. i have no idea where to start. for instance, one of my inputs' code is for a first name input where the first letter has to be capitalized. the code is:

<div class="FirstName">First Name:
<input title="First Name With first letter Capitalized"
name="FirstName"
placeholder="Dalton"
type="text"
pattern="[A-Z] {1} [a-z] *"
class="check"
id="FName"
tabindex="1"
required />
</div>

plus, i want it to be validated on the push of this button:

<div class="validate">
<input type="submit" value="Validate Form and Calculate Tax" /> </div>

so i have a function in javascript called "Calculate ()" which is where i want to put the if statement. anyone have any suggestions?
 
Can do something like:

Code:
var yourString = "Carnage"

if(yourString.charAt(0) != yourString.charAt(0).toUpperCase())
{
    alert("String must start with a capital letter!");
}
 
Can do something like:

Code:
var yourString = "Carnage"

if(yourString.charAt(0) != yourString.charAt(0).toUpperCase())
{
    alert("String must start with a capital letter!");
}
I dont understand what i would put into the "yourString" part
 
It would be ".Value" instead of ".Text".

You can just condense it to 1 line as well:

Code:
var inputString = document.getElementById("textbox_id").value
 
Back
Top Bottom