How to validate user input for mobile number using Regular Expression in Javascript

InfoPath alternatives for form designing SharePoint

The below Html code explains the client side validation for mobile number using Regular Expressions.

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head runat=”server”>

<title>Untitled Page</title>

<script language=”ecmascript” type=”text/ecmascript”>

function validateMobileNo() {

var p1 = /^([0-9]{10})$/;

var mobile_no = form1.Text1.value;

var x1 = mobile_no.match(p1);

if (x1 == null) {

alert(“Invalid User Input”);

return false;

}

return true;

}

</script>

</head><body>

<form id=”form1″ runat=”server”>

<div>

Enter Mobile Number:

<input id=”Text1″ name=”txt1″ type=”text” /><br />

<br />

<asp:Button ID=”Button2″ OnClientClick =”return validateMobileNo();” Text=”MobileNoCheck” runat=”server” />

</div>

</form>

</body>

</html>

Hope this post was helpful. Also, you can read some SharePoint online tutorials:

– Download FREE PDF on HUB site in SharePoint online


– Apply HTML to email template in SharePoint 2010 designer workflow

– Delete custom page layout in SharePoint 2010


You May Also like the Following SharePoint Online Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply