2

I have requirement for my input in the form... my valid values are number or "No Min" or "No Max". now I can use pattern for string value or number but not both... my question is how can i use multiple pattern in html 5 input tag... I am also using jQuery...

 <form id="form_searchProperty"  >
  <div class="criteria_block">
   <span><label class="search_form_Label" for="propbath">Bathroom</label></span>
     <span>
          <input id="input_propbath_min" value="No Min" pattern ="\d+" name="Min_Bathrooms" style="width:75px;"/>
          <input id="input_propbath_max" value="No Max" pattern ="\d+" name="Max_Bathrooms" style="width:75px;" />
      </span>
    </div>
  </form>
4
  • You are already using the select element for this, which restricts what a user can choose by a dropdown. I don't see the benefit of using the pattern attribute in this case. Commented Jun 6, 2013 at 19:21
  • so sorry Mat, i have pasted wrong code.... is my using input!!! see code above thanks Commented Jun 6, 2013 at 19:29
  • 2
    Can you instead make the field not required and accept an empty input as "no min"/"no max"? Commented Jun 6, 2013 at 19:31
  • no is because No Min tag is for user to show, by putting 0, many may not understand... although No Min, I am taking as 0 once the form is submitted ... Commented Jun 6, 2013 at 19:46

4 Answers 4

19

You can use the OR (|) operator.

pattern="(No M(in|ax))|\d+"
Sign up to request clarification or add additional context in comments.

Comments

2

Since your pattern is a regular expression, your regex pattern can have an either/or in it:

<input pattern ="(\d+)|(No Min)">

Comments

0

you can use regular expression test instead of pattern property of input element.

see this:

<script src="jquery-1.8.0.min.js"></script>
<script>
$(function(){

    $('form#form_searchProperty').submit(function(){
        var pat1 = /\d+|no min/i, pat2 = /\d+|no max/i;
        if (!pat1.test($('#input_propbath_min').val()) && !pat2.test($('#input_propbath_min').val()))
        {
            return false;
        }
    });

});
</script>

<form id="form_searchProperty"  >
    <div class="criteria_block">
        <span><label class="search_form_Label" for="propbath">Bathroom</label></span>
        <span>
            <input id="input_propbath_min" value="No Min" name="Min_Bathrooms" style="width:75px;"/>
            <input id="input_propbath_max" value="No Max" name="Max_Bathrooms" style="width:75px;" />
        </span>
    </div>
    <input type="submit" >
</form>

Comments

0

you can use in this format

<input type="text" pattern="10453|10457" />

Add as many number as you want with the | sign.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.