Is it possible to have a input pattern with 2 options?
For example. I have a field where a user enters an extension number (4 Digits) eg. 7483 BUT Some people have 2 extensions eg. 7483 / 7542
Is there a way to set the input pattern so it can either be 4 characters or 11? And otherwise show a error message?
This is what I have so far:
Extension:<br><input type="text" name="extension" required
pattern= "{4}" title="Please Enter the Extension Number/s"><br />
You can use jQuery Form Validator lib & write custom validator for it. For validation you should use /^\d{4}( \/ \d{4})?$/ pattern.
Here is the complete solution. Read it thorough & stick with RegExp! ;-)
<!DOCTYPE html>
<html>
<head>
<title>Custom Validation</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="" method="post">
Extension:<br />
<input type="text" name="extension" required
data-validation="custom" data-validation-regexp="^\d{4}( \/ \d{4})?$" title="Please Enter the Extension Number/s"><br />
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>
<script>
// Setup form validation
$.validate();
</script>
</body>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With