0

I have a DHCP Scope input

<input name="dhcpscope" type="number" min="1" max="254" ng-model="dhcpscope" maxlength="3" size="3" ng-required="true">

It works perfectly for DHCP scope range from 1-254, but I also want to exclude the number 111.

How do I do that? Is there another HTML attribute that I can use?

Unless, Angular RegEx ng-pattern is the only way to go about this ...

code-8
  • 54,650
  • 106
  • 352
  • 604
  • you might want to consider something like this ? `if(/^(?!(111))/.test(str)) { }` – JBone Sep 20 '17 at 19:19
  • can you just toss this pattern: https://www.w3schools.com/tags/att_input_pattern.asp in with the min/max? ^(?!.*111).*$ I'm not sure how range and pattern work together, just an idea. – sniperd Sep 20 '17 at 19:28
  • You can match that number range with a regex pattern but it will be kind of scary looking https://regex101.com/r/Pq7WnB/2 – CAustin Sep 20 '17 at 19:28

1 Answers1

0

This is one way to do it. Use JavaScript. Call function onchange and just do the same thing for any number you want to remove inside that function, I did it for 3 and 6. Enjoy!

var lastnum = 1;

function myFunction(x) {

  if (x.value == 3 && lastnum < 3) {
    x.value = 4;
  } else if (x.value == 3 && lastnum > 3) {
    x.value = 2;
  }

  if (x.value == 6 && lastnum < 6) {
    x.value = 7;
  } else if (x.value == 6 && lastnum > 6) {
    x.value = 5;
  }

  lastnum = document.getElementById("myNum").value;
}
<input name="dhcpscope" type="number" min="1" max="254" ng-model="dhcpscope" maxlength="3" size="3" ng-required="true" value="1" id="myNum" onchange='myFunction(document.getElementById("myNum"))'>
Djordje Vujicic
  • 414
  • 5
  • 20