Here is my effort
Been playing around with prototypes of late so I thought this would be fun
<script>
String.prototype.hasCrap = function () {
var inStr = this.match(/[^a-zA-Z0-9]/g);
if (inStr)
{return true;}
else
{return false;}
return true
}
str = "thisisastring";
alert(str.hasCrap())
str = "this is a string";
alert(str.hasCrap())
</script>
This way the hasCrap() function becomes a method of the String object, so you can call
hasCrap() as a method of any string
So in your case
if (document.particulars.username.value.hasCrap()) {
alert('Please Enter a Username');
return false;
}
Regards
Steve Onnis
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Brad Apps
Sent: Wednesday, August 11, 2004 4:18 PM
To: CFAussie Mailing List
Subject: [cfaussie] Help with validation code...
Hi All,
Just wondering if you could give some help with some javascript code
please. I have some form validation code which simply sees if a field is
empty or not:
if (document.particulars.username.value == "") {
alert('Please Enter a Username');
return false;
}
But what can I add to see if the username field contains the character ';'
or has any spaces. If it does contain any of these, it must bring up an
error.
Help would be greatly appreciated.
Thank you.
---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/
---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/