EnjoySharePoint YouTube Channel

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

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

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

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” “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 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();” />





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

Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint 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 →