Text field with alphabet restriction

i want textfield .. like nobody can enter number in it. if somebody try to enter number show message...

i don't want in javascript... just in html
deepakabcAsked:
Who is Participating?
 
hieloConnect With a Mentor Commented:
Yes, it's working. It gives the message as soon as the user clicks or tabs out of the text field. The example below gets rid of the non-alphabetic characters AND notifies the user as well.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript"><!--
function validate(obj)
{
 
	if( false === /^[A-Z]+$/i.test( String(obj.value) ) )
	{
		alert("Only alphabetic characters are allowed.");
		//clear the invalid value
		obj.value=obj.value.replace(/[^A-Z]/ig,"");
	}
}
//--></script>
</head>
<body>
<form name="theForm">
<input type="text" name="sample" value="" onblur="validate(this)"/>
</form
</body>
</html>

Open in new window

0
 
hieloCommented:
Not doable without scripting. HTML is just markup. The scripting is what makes the page "interactive". Basically the page needs to "react" to the user input. Without scripting, this is a dead end.
0
 
boro_bobCommented:
Hielo is correct. There is no way of doing this without using javascript and a regular expression.

Have a look at this web page for more information on how to do it.

http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
simply_dhavalCommented:
not doable with simple html  as they said alredy

may be you should explore the html DTDs more, to check it out

may be you can try  xhtml which have document design in xml but then to represnt the content you will have to use xslt
0
 
deepakabcAuthor Commented:
i tried with javascript but still not working can u give me more code to help in validation
0
 
hieloCommented:
Take a look at this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript"><!--
function validate(obj)
{
 
	if( false === /^[A-Z]+$/i.test( String(obj.value) ) )
	{
		alert("Please supply only alphabetic characters.");
		//clear the invalid value
		obj.value="";
	}
}
//--></script>
</head>
<body>
<form name="theForm">
<input type="text" name="sample" value="" onblur="validate(this)"/>
</form
</body>
</html>

Open in new window

0
 
deepakabcAuthor Commented:
This code is not working sorry
0
 
simply_dhavalCommented:
have you enabled java script in your browser ?

and you may have to twist the code a bit depening upon your browser specifically there is noticeable difference when you test codes on mozilla and ie
0
 
deepakabcAuthor Commented:
i tried in both internet and firefox but still code is not working...

all i do i copy and paste the code in the html file and try to run it.. but it took character without warning message
0
 
simply_dhavalCommented:
can you just show me screen shot of what you get in browser ?
0
 
deepakabcAuthor Commented:
check it out
screenshot.jpg
0
 
deepakabcAuthor Commented:
thanks
0
All Courses

From novice to tech pro — start learning today.