How to validate First Name and Last Name in one input textbox using javascript?i have one inputtext box.when i given first b=name then need to give one space and need to give lastname.when i given two spaces or more spaces after firstname need to validate lasname is required and remove all spaces and put one space between firstname and lastname.can anybody help me this.
Visualforce page:
<apex:inputtext value={!name} id="Name"/>
<apex:commandbutton onclick="validatenamevalue();"/>
javascript:
function validatenamevalue(){
var name = document.getElementById('{!$Component.formId.Name}').value;
if(name == '') {
alert(firstname is required);
} else if(!name.includes(' ')) {
alert(last name is reqiured);
}
}
when i given second space empty value is saving in lastname field.need to validate lastname is not empty.
apex:inputText
needs to have value in double quotes i.e.<apex:inputtext value="{!name}" id="Name"/>