The semantic UI form validation I'm implementing uses a regex rule of 'regExp[/(.*[0-9 \\-]){23}$/]'. Works perfectly on all devices except for iOS

Here is the code snippet provided that accepts a card number in the format 5077-1200-5007-3284-951. The card number works on all devices/browsers except for iOS. Additionally, I would like to know if there is an alternative regex pattern I can use for the same input format.

<html>
<link rel="stylesheet" type="text/css" href="css/semantic.min.css"></link>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/semantic.min.js"></script>

<body>
  <div class="field example">
<form class="ui form">
    <div class="field">
      <label>Card Number</label>
      <input id="name" name="cardNumber" type="text">
    </div>

    <div class="ui submit button">Submit</div>
    <div class="ui error message"></div>
  </form>
</div>
</body> 
<script>
  $('.field.example form')
  .form({
    on: 'blur',
    fields: {
      empty: {
        identifier  : 'empty',
        rules: [
          {
            type   : 'empty',
            prompt : 'Please enter a value'
          }
        ]
      },
      cardNumber: {
                        identifier: 'cardNumber',
                        rules: [{
                            type: 'empty',
                            prompt: 'Required'
                        },
            {
                            type: 'regExp[/(.*[0-9 \-]){23}/]',
                            prompt: 'Invalid'
                        }]

                    },
      checkbox: {
        identifier  : 'checkbox',
        rules: [
          {
            type   : 'checked',
            prompt : 'Please check the checkbox'
          }
        ]
      }
    }
  })
;
  </script>
<html>

Answer №1

If you want to give it a shot, you can attempt this:

^(?:\d{4}-){4}\d{3}$

This regex breakdown might help:

  • ^, $ - Indicates the beginning and end of a line, respectively.
  • (?:\d{4}-){4} - Represents a group that does not capture, matching four digits followed by a - exactly 4 times.
  • \d{3} - Matches the digit exactly 3 times.

https://i.sstatic.net/5RaTY.png

You can take a look at a demonstration of this regex here.

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

Deleting a page reference from the page history stack in Angular 4

I am working on my angular web application and I am looking for a way to remove a specific page reference from the angular page history stack. For example, if I navigate from the login page to the dashboard page, I want to remove the login page reference f ...

What is the process for showing information on a subsequent screen?

My goal is to show a list of employees after conducting a search. It currently works fine, but I aim to enhance my code to display more details on a second page when the user clicks on a cell or a button next to it. Here is the code snippet: <form act ...

Discover every item that begins with 'button-'

Currently, I am utilizing Selenium to retrieve all ID elements that begin with "button-". My initial approach involved using regex to locate the "button-" but unfortunately, I encountered an error message stating that TypeError: Object of type 'SRE_Pa ...

Searching for the closest jQuery value associated with a label input

As a beginner in JQuery, I am looking to locate an inputted value within multiple labels by using a Find button. Below is the HTML snippet. Check out the screenshot here. The JQuery code I've attempted doesn't seem to give me the desired output, ...

JavaScript Regular Expression that identifies commas enclosed within quotation marks

I am attempting to parse a text-based log file in the following format: type: 'click', category: 'REFRESH_DOOR', desc: 'clicked refresh from door 0124', site: 'mysite', pathname: '/load_areas/all/doors&apos ...

Error: unexpectedly encountered a nil value while unwrapping an Optional in UITextField, causing a fatal error (lldb)

In my LoginViewController, I have a viewDidLayoutSubviews() function where I am trying to create a bottom-only border for a text field. Here is the code I am using: let txt_border = CALayer() let txt_pass_border = CALayer() let border_width = CGFloat(2.0 ...

Change the local date and time to UTC in the format of yy:mm:dd H:M

I must change the date format from local time to UTC or ISO as yy:mm:dd H:M, or calculate the difference between local date times with 03:30 as yy:mm:dd H:M 2016-10-22T04:30:00.000Z convert this to 2016-10-22T01:00:00.000Z ...

Please be aware that any fabricated comments will not be displayed in the posts object

-I have made an EDIT at the bottom of my original post -For my plunker, please visit this link Currently, I am learning AngularJS by following a tutorial located here. At this moment, I am stuck on the step called 'Faking comment data'. I have ...

Having difficulty in compressing Vue.js application

My Vue.js Application contains the following code snippet: (function() { initApp(); })(); function initApp() { window.myApp = new Vue({ el: '#wrapper', data() { return { somedata: [] } } }); } & ...

Using Mongoose to delete multiple documents with the "like" operator

I am looking to remove all documents from a MongoDB collection that have a particular string in one of the fields. (I am working with mongoose) In SQL terms, the equivalent query would be: DELETE FROM users WHERE name LIKE '%test%' ...

Having trouble making a table in Vue3 update responsively? Consider using Axios to request updated

My goal is to update a table dynamically using data from a Google Maps query of nearby areas. The query successfully retrieves the correct data in the onMounted lifecycle, but fails to display or return the data during rendering. I have experimented with ...

When displaying multiple images using HTML5 Canvas in a for loop, only the final set of images is drawn

I'm facing an issue with drawing images using an image loader inside a for loop. The images are only being drawn on the last iteration. The console is not displaying "draw -> 0" or "draw -> 1", it only shows "draw -> 2" Any assistance would ...

Definition in Typescript: The term "value is" refers to a function that takes in any number of arguments of

export function isFunction(value: any): value is (...args: any[]) => any { return typeof value === 'function'; } What is the reason behind using value is (...args: any[]) => any instead of boolean ? ...

Utilizing Angular.js to Bind AJAX Content to Web Pages

I recently experimented with coding using angular.js version 1.5. <div class="container clearfix" id="mainMenu" ng-controller="MainMenuController as mainMenu"> <ul class="menu clearfix" ng-init="tab = 'ant'"> <li class ...

Concealing the submit button until a file has been selected

How can I make the submit button invisible until a file is selected? <form action="upload.php" method="POST" enctype="multipart/form-data"> <input type="file" name="imageURL[]" id="imageURL" /> <input type="submit" value="submi ...

Exploring the functionalities of Ajax and HTML5 history states in relation to back button behavior

There have been numerous inquiries regarding the functionality of pushState in HTML5, but I'm encountering two specific issues for which I haven't found any solutions. My popstate handler is defined as follows: $(window).bind('popstate&apos ...

What is the best way to have multiple meshes traverse various paths at a consistent speed simultaneously?

Scenario In my game development project, I have a community where multiple characters need to move autonomously and complete tasks. I implemented a method found in this resource for moving objects along a path using Three.js. However, each character moves ...

Using jQuery with Rails 3 for Efficient Callback Handling

I have been working on creating my own custom confirm dialogs that take two parameters. function myAlert(message, address) { jConfirm(message, 'Confirmation Dialog', function(response) { if (response){ window.location = a ...

Is there a way to efficiently add delimiters to an array using jquery dynamically?

Just joined this community and still figuring things out. I have a question - how can I use jQuery to dynamically add a delimiter like "|" after every 3 elements in an array? This way, I can explode the array and utilize the resulting arrays separately. He ...

Efficiently Managing Errors on REST Server

My application has the ability to generate a PDF on demand through service/generatePdf. The response includes content-type="application/pdf" with binary contents in the outputStream. According to business requirements, clicking a button should open a new ...