The correct pattern must not be matched by ng-pattern

Within the ng-pattern attribute, we can define a specific pattern for a field to match.

Is there a way to indicate that the field should NOT match the specified pattern?

For instance:

<input type="text" ng-pattern="/[*|\":<>[\]{}`()';@&$]/" />

In this case, I intend for the field not to conform to the pattern. Instead, I want an error to be displayed if the pattern is matched.

Answer ā„–1

To reverse the effect of the regular expression, you can employ a negative lookahead ((?!pattern)):

ng-pattern="/(?![*|\":<>[\]{}`()';@&$])/"

Answer ā„–2

If you want to determine whether a string lacks a specific substring, you can employ a lookahead anchored to the start of the string:

/^(?!.*[*|\x22:<>[\]{}`()';@&$])/

For AngularJS, if a RegExp object is used (the one enclosed in delimiters), the pattern does not need to cover the entire string. Therefore, this regex is suitable for the current requirement of verifying a condition as true or false.

Keep in mind that the commonly suggested tempered greedy token solution

^(?:(?![*|\x22:<>\[\]{}`()';@&$]).)*$
(refer to demo) can also be utilized, but it is less efficient as it requires checking each position in the input string.

Additionally, using \x22 to match a double quote in the ng-pattern value is recommended.

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

Implementing Kendo UI dataSource to interact with a PHP function

Greetings Everyone, I have a category.php file within my code that handles CRUD functions. However, I am unsure how to call these functions in the Kendo UI dataSource/transport. Previously, I had separated the PHP files, but now I want to consolidate them ...

When a URL is entered, information is not retrieved from the database

I have a simple app setup where the data (iPhones from the database) is fetched in the AppComponent itself. ngOnInit(): void { this.iphoneservice.fetchIphones(); } The fetchIphones method is located in my iPhoneService file and consists of 3 functio ...

"Here's a simple guide to generating a random number within a specified range

I have encountered a specific issue: Within an 8-column grid, I am attempting to randomly place an item with a random span width. While I have successfully managed to position the item and give it a random width, I am struggling with adjusting the width b ...

Having troubles retrieving the selected option with AngularJS

Looking to retrieve the chosen option from a select tag using Angular JS. Currently, the attribute value is returned as "1, 2..", but I require it to be "one, two.. when the select tag is changed. Below is a snippet of my code: JS var app = angular.modu ...

The CSS selectors wrapped in jQuery vary between Chrome and Internet Explorer 11

When utilizing a jquery wrapped css selector such as $($("#selector").find('input[type="textarea"])'), I am able to input values into the textarea in Chrome using $($("#selector").find('input[type="textarea"]).val(someValue)') but encou ...

ngSelected is not affecting the value of ngModel in AngularJS

Below is a select list with an ngSelected attribute that correctly selects the value in the expression, but the model for the select does not update accordingly. Even though I can select the "High" Value and trigger the ngSelected, the display shows an emp ...

Before each existing DIV in a loop, a new div is inserted using the insertBefore

const len = document.getElementById('parent').children.length for (let i = 0; i < len; i++) { const div = document.createElement("div"); document.getElementById('parent').insertBefore(div, document.getElementById('parent' ...

Encountering the "ExpressionChangedAfterItHasBeenCheckedError" in Angular 2

As I try to fill in multiple rows within a table that I've created, the table gets populated successfully. However, an error message pops up: "ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous valu ...

Troubleshooting Problem in Coursera's AngularJS Week 3 Exercise 4

Here's the issue I'm facing: After launching the index page with 'gulp watch', there's nothing visible on the screen. An error appears: Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.12/$injector/modulerr?p ...

Organizing MVC5 with Angular JS: How to Create an Effective Folder Structure

As someone new to Angular and eager to learn best practices, I'm wondering about the ideal folder structure for an ASP.NET MVC5 AngularJS application. MVC5 default layout - Controllers Folder - Models Folder - Views Folder ---> Action Name Folder ...

How to Spin an Image in the Canvas Using HTML5

I am having trouble rotating an image inside a canvas after researching similar questions on Stack Overflow. Here's what I've learned: It seems I cannot rotate a single object inside the canvas. I can only rotate the entire canvas itself. ...

Guide on inserting the elements <label>, <input>, and <span> into a <li> in a particular sequence

var btn = document.querySelector('.add'); var remove = document.querySelector('.draggable'); function dragStart(e) { this.style.opacity = '0.4'; dragSrcEl = this; ...

Utilizing MVC Models to Control Angular Material Checkbox Functionality

I'm getting familiar with the concept of MVC and I've started using MVC5 in combination with angular-material. My goal is to incorporate an MVC model variable with an angular material checkbox (md-checkbox). Below is my code snippet for implemen ...

Message display showing an "[object Object]" (Node Express Passport)

Having an issue with my passport.js implementation where the flash message is not showing up when the username or password is incorrect. The logic was working fine before, but now it's broken even after copying the working version step by step. Flash ...

Execute a function upon mounting of an API endpoint

I have been working with an Express router in my application. I am trying to execute a function when a specific route is mounted. The setup involves two files, index.route.js and currentUser.route.js. index.route.js import currentUserRoutes from './ ...

Navigating through error messages in NextJs 14 can be tricky, especially when faced with the dreaded "ReferenceError: document not defined" or "prerendering error". It's vital to pinpoint exactly which page

When attempting to run the build on my Next.js application, I encountered an error message that is not very informative given the number of files/pages in my project. How can I pinpoint the exact location of this error and determine the root cause? The pro ...

The success function of the Ajax request remains untouched by the response

My ajax call isn't triggering the success:function(resp){ ...} Despite receiving a response status of 200 and a non-null Json response. This is my ajax setup: $.ajax({ url: '/url/', type: 'GET', data: { pass_ ...

Leveraging AngularJS and PhoneGap for seamless Facebook login/SDK integration even without the need for a server

In the process of developing a web application that will be deployed with Phonegap, I am utilizing NodeJS on the backend and AngularJS on the frontend, incorporating Facebook authentication. Currently, the Node server is running at localhost:3000 (will eve ...

Customizing the initial page layout in Elm

I am new to Elm and I need help with a particular issue. Can someone provide guidance or direct me to a useful resource for solving this problem? The challenge Iā€™m facing involves editing the start page of a website by removing specific elements, as list ...

Error message: Icons failing to display in conjunction with template output | 404 error code

I'm trying to display icons based on a search, but I keep getting a 404 error for http://localhost:3000/static when I input a value. My current folder structure looks like this: Root directory > Public > Icons and Root directory > index.js. ...