javascript - Name should have albhabet only -
i have wrote code validate name,whether has albhabet throw error if not have albhabet below code should show error,but not show error message
var nameexpression = '/^[a-za-z]/'; var name = 'hello123'; if ( !nameexpression.test(name) ) alert('error:please enter valid name');
var nameexpression = /^[a-za-z]+$/; var name = 'hello123'; if ( !nameexpression.test(name) ) alert('error:please enter valid name');
explanation: 1.nameexpression should not string 2. should use end delimeter such '$' eg var nameexpression = /^[a-za-z]$/;
Comments
Post a Comment