Print Page | Close Window

Validation

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Web Design Discussion
Forum Description: Discussion on web design and development subjects.
URL: https://forums.webwiz.net/forum_posts.asp?TID=2872
Printed Date: 29 March 2026 at 10:53am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Validation
Posted By: karp13
Subject: Validation
Date Posted: 20 May 2003 at 7:58am

I need to validate that the contents of a form text field start with DTP.  This field will be for serial numbers that all start with these 3 letters.  Also this field is not required.  It only needs to be validated if something is entered in it.

How would I do this?

Thank you in advance!

Karp13




Replies:
Posted By: ultramods
Date Posted: 20 May 2003 at 10:57am

Try this:

<html>
<head>
<script name=javascript>
function checkInput(inputText)
{
var error

error = "ok";

//use the following line if the input isnt case sensitive
//inputText = inputText.toUpperCase();

if (inputText.length > 0)
{
 if (inputText.substr(0,3) != "DTP")
 {
  error = "There was an error.";
 }
}

alert(error);

}
</script>
<title>Untitled Document</title>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
  <input type="text" name="textfield" onBlur="checkInput(this.value)">
</form>
</body>
</html>



Posted By: karp13
Date Posted: 20 May 2003 at 12:25pm

Perfect!!

Thanks



Posted By: abhinav
Date Posted: 19 June 2003 at 6:39am
I am a javascript learner .. thx for that script from me too =)

-------------
http://www.sgkabra.com - Accountancy Firm | http://www.mp3oldies.com.ar - Mp3 Oldies | http://www.best-mp3software.com - Mp3 Software



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net