HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 10th, 2000, 09:37 AM
chux007 chux007 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 2 chux007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am trying to validate a file name field where I only want certain image extensions to be entered...say...
png, jpg, gif, and tif
how would i check teh substring...do i use indexOf()?
please provide syntax..thanx

Reply With Quote
  #2  
Old July 13th, 2000, 11:51 PM
billyo billyo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 114 billyo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Regular expressions can make form validation a snap. You can them use to validate fields in ways you've never imagined. I made a little page for myself to help me write them. It's based on an article at this site. If you want to change the expression though, you have to do it in the html. I'm gonna put the page I wrote in here with a regular expression that only accepts the four extensions you listed in your post.
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre><html>
<head>
<script language=JavaScript><!--
function Validate()
{
// obtain form value into variable
var thing= document.all.thing_to_test.value;

// define regex
//for currency var pattern = /(^[$d])+([,d])+([d]$)/;
var pattern = /.jpg$|.gif$|.png$|.tif$/

// test for pattern
flag = pattern.test(thing);

// pattern.test returns a boolean
if(flag)
{
document.all.results.value="pattern matches"
//return true; use these for a form
}
else
{
document.all.results.value="pattern doesn't match"
//return false;
}
}
--></script>
<style><!--
td, button
{
font-size:10px;
font-family:Arial;
}
--></style>
</head>
<body bgcolor="0099ff">
<table bgcolor=000000><tr><td>
<table bgcolor=ffff00>
<tr><td colspan=2>
Regular Expression Tester
</td></tr>
<tr><td>
test this
</td><td>
<input name="thing_to_test" type="text">
</td></tr>
<tr><td>
result
</td><td>
<input name="results" type=text>
</td></tr>
<tr><td colspan=2>
<button style="background-color:0099ff;font-weight:bold;width:220;" onclick="Validate();">Test The RegEx Pattern</button>
</td></tr>
</table>
</td></tr></table>
</body>
</html>[/code]
Here's the link to the article: http://www.devshed.com/Server_Side/...tration/RegExp/
Have Fun. (That thing's untested in netscape, and of course it won't work with the document.all...)

[This message has been edited by billyo (edited July 13, 2000).]

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > form validation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway