How to validate user input to accept only 10 character using Regulat expressions in Javascript

InfoPath alternatives for form designing SharePoint

The below Html code explains the validation for name which accepts only

lower case and upper case alphabets using Regular Expressions

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

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>

<html xmlns=””>

<head runat=”server”>

<title>Untitled Page</title>

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

function validateEmpName() {

var name = document.getElementById(” <%=empName.ClientID%>”).value;

// Reg Exp to accept only A-Z and a-z

var p1 = /^([A-z])+$/;

var x1 = name.match(p1);

if (x1 == null) {

document.getElementById(“empName”).style.color = “red”;

alert(“Employee name is not in the corrrect format”);


return false;


return true;




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


Enter Employee Name:

<asp:TextBox ID=”empName” runat=”server” Width=”132px”></asp:TextBox>

<asp:Button ID=”Button1″ runat=”server” Text=”Check Name”

OnClientClick = “return validateEmpName();” />





Similar SharePoint 2013 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

View all posts by Bijay Kumar →

Leave a Reply