Angular input field for IP addresses with a mask applied

Incorporating angular/ui-mask into my current project has been helpful, but now I am looking for a way to mask IP address ranges (ex. 192.168.70.18/20). Here is what I have so far:

 <input  ng-model="address" ui-mask="9?9?9.9?9?9.9?9?9.9?9?9/9?9" ui-mask-placeholder-char="_" placeholder="" ng-disabled="disabled">

The issue is that it only allows me to enter one specific IP address: 192.168.125.254

Here is the link to my jsFiddle page for reference: http://jsfiddle.net/Sheinar/Lvc0u55v/6133/

Answer №1

Here is a potential solution to your issue:

$scope.$watch('address', function (address) {
    if (!address || address.length < 15) return;

    var endFrom = parseInt(address.substr(9, 3)),
        endTo = parseInt(address.substr(12, 3));

    if (endFrom > endTo) {
        alert('range is invalid');
        $scope.address = address.substr(0, 12);
    }
});

Check out this example on JsFiddle for reference.

Answer №2

Begin by installing ngxMaskModule using the command npm i ngx-mask.

Next, include it in the shared module by calling NgxMaskModule.forRoot().

In the HTML file, remember to apply the mask='IP' attribute to the input text field.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The jssor slider cannot be initialized when it is loaded through ajax requests

Incorporating jQuery's .load() function, my website dynamically loads the HTML code for the jssor slider. To verify the functionality of my code, I have developed a duplicate page which already includes the necessary slider code without utilizing an a ...

Is there a way to connect two circles with identical numbers using Javascript and HTML?

My latest project involves creating a fun program that generates 4 balls on the screen, each with a unique number displayed inside. Users can input their desired values for new circles to be generated and then click a button to see four more balls appear ...

Buttons within the Bootstrap carousel caption cannot be clicked

I am currently designing a webpage with a Bootstrap carousel that includes a paragraph caption and two buttons. However, the buttons are not functioning as clickable links - when clicked, nothing happens. {% block body %} <div id ="car-container"> ...

Reorganize JSON data in JavaScript

I am in the process of creating a tree structure, and I want it to be organized in the order of name, desc, then children. However, the JSON data I have received is not in this order. Is there a way to rearrange it efficiently or perhaps optimize the code ...

Learn to create customized HTML elements in HTML and control them with JavaScript

I am looking to dynamically create an HTML object and replicate it N number of times using JavaScript. Below is an example of the object I want to generate multiple times on an HTML page: <div class="row"> <div class="column" style="backgroun ...

Message displayed within Ng-repeat loop

Having trouble implementing a tooltip within an ng-repeat for each item in a td element. Whenever the mouse hovers over an item inside the td, I want a tooltip to display with more details. The code below shows my setup, using ng-if to prevent displaying e ...

Building a Java application that utilizes a JSON object

I am trying to convert a JSON format into Java code using JSONObject and JSONArray, but I am facing difficulties in getting the output in the desired format. The JSON format is provided below: var transaction_Data = [ { "key": "PASSED", "valu ...

What could be the reason for the input field not updating the Angular model upon changes?

I have a question that might be considered beginner-level, but I am curious as to why document.getElementById("demo").value doesn't update the angular model. It does update the input field, however, it only updates the model after something is ...

Incorporating list items in a React component is not functioning as expected

When I console.log(this.props), here are my props: list:Array(1): {user: "Jack Nicholson", userid: "5b684ed8d3eb1972b6e04d32", socket: "1c0-Jb-kxe6kzPbPAAAD"} However, despite mapping through my list and using the component <UserItem user={user.user} ...

Inadequate grid data retrieval (This problem arises randomly)

During the process of loading data in a grid on our production server, I encountered a script error at the bottom left corner of the page. Interestingly, this error only occurs on the production server and works perfectly fine on the local server. Here ar ...

Tips for transferring <form> information to an object array within a React application

I am currently working on a basic component that takes an input message, displays it in a list below the input field when submitted. However, I am facing an issue where clicking the submit button only results in a blank bullet point appearing below. impo ...

What is the best way to retrieve information from an array of objects and store them in individual variables?

I'm struggling to extract the necessary information from the array below, which was received from the backend. I need to utilize these values as error messages but my attempts to map have been unsuccessful. const errorArray = [ { "candidate ...

A guide on conducting comparisons within a render in React

Currently, I am placing a component inside another component and the setup is shown below: render() { return ( <MyComponent value={this.state.measurement.Value} unit="kg" /> ); } My objective is to m ...

Selecting the child checkbox within the parent div using ng-click

Is there a way to trigger the click event of a parent div on its child checkbox in AngularJS? The Checkbox will have the attribute hidden, necessitating the parent div to act as the clickable element. Sample HTML: <body ng-app="checkboxApp"> ...

Is there a way to remove this illicit JavaScript character from the code? It is appearing during execution

I am in the process of creating a custom tooltip using Microsoft Chart Controls. These controls provide support for using keywords to automate the data you want to display. For instance, string toolTip = string.Format("<div> {0}: {1} {3} ({2}) ...

loop through the links using their unique identifiers

Here is my current code in Jade/Pug: #pm_language.dropdown(aria-haspopup='true', aria-expanded='false') button#langbutton.btn.btn-primary.dropdown-toggle(type='button', data-toggle='dropdown') Lang [RU] ...

Issue with Visual Studio Code and Chrome Debugger regarding unconfirmed breakpoint

Apologies if this question has been asked before, but I've gone through the existing answers and still can't find a solution. I am currently working on an older AngularJS application that has been partially migrated to Typescript. The source fil ...

The Next JS build process exclusively creates server-side pages

I have noticed that some of my pages like /contact, /about, and /rules are server-side generated even though I am not using getServerSideProps(). Since these pages only contain static images and text without any API requests, I want them to be treated as s ...

Connecting a specific URL of an API to a single mobile app: A step-by-step guide

Currently, my API includes a user registration system that is utilized by a mobile application. Most of the URLs are restricted for anonymous users and require a token key for authorization, except for the register URL. The register URL needs to remain op ...

Tips for ensuring a webpage loads at a specific resolution

I recently created a website on my computer with a screen resolution of 1920x1020. However, when I view it on other machines with a 1366x768 resolution, the website appears distorted. Is there a way to set a fixed resolution for my website to ensure it l ...