What are the steps to implement email validation, Saudi mobile number validation, and national ID validation in cshtml?

Looking to implement validations for the following fields: email, mobile number (must be 10 numbers and start with 05), and National ID (must be 10 numbers and start with 1 or 2)

<input class="form-control" type="text" id="txtNID" name="NID">

<input class="form-control" type="text" id="txtMobile" name="mobileNumber">

<input class="form-control" type="email" id="txtEmail" name="email" >

<input type="button" id="btnSend" class="btn btn-view" value="send" />
                                

Answer №1

When it comes to UI validation, utilizing attributes of the input tag such as 'minlength', 'maxlength', and 'pattern' is essential:

<form>
    <input class="form-control" pattern="05.*" minlength="10" maxlength="10"  type="text" id="txtNID" name="NID">
    <input class="form-control" pattern="[12].*" minlength="10" maxlength="10"  type="text" id="txtMobile" name="mobileNumber">
    <input class="form-control" type="email" id="txtEmail" name="email" >
    <input type="submit" id="btnSend" class="btn btn-view" value="send" />
</form>

Furthermore, don't forget to implement server-side validations for added security.

To delve deeper into input tag attributes, check out this resource: https://www.w3schools.com/tags/tag_input.asp

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

What are the steps to refreshing a table using AJAX?

Struggling to update a table from my database, I have been following a PHP guide but can't get it to work. In a separate file, the data is retrieved and displayed in a table. I am attempting to use JavaScript to refresh this file. This code snippet ...

Filtering with XML parsing

My XML file has the following structure - <?xml version="1.0" encoding="UTF-8"?> <prj:Flow xmlns:prj="url1" xmlns:com="url2" xmlns:ns2="url3" xmlns:con="url4" xmlns:ns0="url5" xmlns:ns1="url6" xmlns:ns3="url7"> <prj:str> &l ...

Utilize React hooks to efficiently filter multiple JSON requests

I am currently working on creating a filter system that can combine multiple filters for users to choose from, such as "big/not-big" and "heavy/not-heavy". Each filter corresponds to loading a JSON file. My goal is to merge the results of these JSON files ...

Enhancing User Experience with Animated jQuery Progress Bar

I came across a cool tutorial on animating progress bars: The only issue was that the progress bar didn't utilize jquery, and there wasn't information on linking multiple buttons to it. After some searching, I found another tutorial that address ...

How can I extract text from HTML tags that contain nested HTML using C#?

<Item> </c>Text i need</c> </c>Text i need</c> </c>Text i need</c> </Item>Text i need</Item> </Item>Text i need</Item> </Item>Text i need</Item> </Item> i need to extract ...

Guide on storing a promise response in an external object in VUE

I am currently working on integrating the higchart network graph in vue. Everything seems to be functioning properly with static data. However, when I attempt to retrieve data using axios, it fails to work. export default { data() { return { ne ...

What could be causing the issue with the array.push method not functioning

i have come across this piece of code function fetchImagesList(errU,errorsList) { if(errU) throw errU; var directories=new Array(); var sourceDir=''; var destinationDir=''; if(errorsList==&a ...

Ways to create a gap between a model's label and the corresponding text field

I am attempting to create a gap between the label and text field using Twitter Bootstrap. Below is the screenshot https://i.sstatic.net/6f8CA.jpg I would like to add some space between User Name label area User Name text field same with other fields. I ...

Leveraging the power of PHP and AJAX for seamless transmission and reception of JSON data through a

I am in the process of creating a basic form that consists of a single text field and a submit button. The goal is to have the entered value posted to a $.getJSON method upon clicking the button, which will then retrieve a JSON response and display it on t ...

C++ displaying results through web interfaces

Is it possible to write a C++ program that displays "Hello World!" on a webpage? #include <iostream> using namespace std; int main () { cout << "Hello World!"; return 0; } And is it possible to integrate this program into an HTML webpage ...

React Native - Scaling images dynamically

I have a responsive photo grid built within a mobile app. I want to display three images across the screen with equal spacing between them. All the images are squares. Unfortunately, using percentages for each image's width and height is not possible ...

Issues with navigating sliders

I've encountered a problem with my slider arrows while following a YouTube tutorial. They are supposed to appear next to the picture and testimonial, but instead, they are showing up at the top. This issue wasn't present initially, but after enco ...

Adjust the width of the button to best fit the content or label

Here we have a screenshot of HTML source code showing a button that is wider than the content it contains. The highlighted area in yellow indicates there is extra space at the right side of the button due to it being displayed on multiple lines. Is this be ...

Show off beautiful text using a styled pre component in a React application

I've been attempting to highlight specific text within a React pre element, but unfortunately, it doesn't seem to be working as expected. Instead of displaying the highlighted text, it shows [object Object]. const Text = styled.pre ` col ...

Constantly showing blank white pages on my website specifically in Internet Explorer 11

I successfully developed a website using react, babel, webpack, and backend Django framework. Everything runs smoothly on Chrome, Safari, and Firefox, but when it comes to IE11, issues arise. Initially, the site functions properly, but after navigating thr ...

What makes componentDidMount the ideal location to initiate AJAX requests?

It is quite common to see AJAX requests being fired at the componentDidMount hook in many React projects. However, I find it hard to understand this suggested practice. For example, consider a component where the AJAX request depends on a prop from the pa ...

What is the best way to locate and extract the content of an HTML element using XPath in Selenium with VBA?

I am currently seeking a solution to extract the content of an element with the name "data-testid" from a website. This specific element appears approximately 35 times within various contexts in the HTML code. The particular element I am interested in look ...

Creating an HTML tag from Angular using TypeScript

Looking at the Angular TypeScript code below, I am trying to reference the divisions mentioned in the HTML code posted below using document.getElementById. However, the log statement results in null. Could you please advise on the correct way to reference ...

Tips for avoiding double reservations and creating time slots with nextjs and prisma

Welcome to my NextJS app booking system. As a beginner, I'm exploring how to create a website for simple bookings and have successfully connected it to Netlify. Currently, I can gather booking details such as time and name using Netlify forms. Howeve ...

Working with multiple onClick events in jQuery

I have multiple onClick events that toggle hide and display classes on various elements when clicked. While it is functional, the amount of code involved makes it appear cluttered and unwieldy. $('.info_2').on('click', function() { $ ...