<input name="phone_no" type="text" id="phone_no" maxlength="11">
<script type="text/javascript">
var f1 = new LiveValidation('phone_no');
f1.add(Validate.Presence,{failureMessage: " It cannot be empty"});
f1.add(Validate.Format,{pattern: /^[0-9]+$/ ,failureMessage: " It allows only numbers"});
f1.add( Validate.Length, { minimum: 6, maximum: 11 } );
</script>
The Javascript is Working but, I need assistance with the following:
- How can i make Phone Number optional and not compulsory because the code will not allow empty textbox during registration completion except phone number is provided.
- How can I disable the Error prompts when invalid entries are entered and instead the invalid entries be automatically clear and focus retained in that textbox ? Because each time the errors are displayed, the phone No textbox is usually displaced or shifted from its initial position in the form.
- In respect of question 2., can the error prompt be transfer for display at the top of the form or elsewhere instead of causing displacement of textbox.
For your question 1:
In all your input field declare an attribute mandatory, and check for its value: if it is true consider that or else leave it