|
-
Sep 5th, 2003, 08:20 PM
#1
Thread Starter
Hyperactive Member
Checking textbox for illegal characters w/ Javascript
I am working on a form, with several text boxes on it. I would like to know how I can go about trying to check for certain characters. Currently I am just checking if the text boxes have something in them. with the following code.
(isEmpty(document.guestform.visitorname.value.toString()))
{ alert("You need to provide a name.");
document.guestform.vistorname.focus(); return false; }
How can I incorportate into this or after this piece of code something that will check if a "\" or a "/" is found. I need to check for this because \ / is not part of a valid name.
I am using javascript.
Thanks to all that help out.
I really appreciate your help.
-
Sep 6th, 2003, 08:02 AM
#2
Fanatic Member
Use a regular expression search to get what you want. Try this example (let me know if you need an explanation of what is happening in "searchpattern"):
Code:
<script language="JavaScript">
var searchpattern = /(\\|\/)+/
function CheckString(FString){
if(FString.search(searchpattern) != -1){
alert("You can not enter a \\ or a / into the field.")
}
}
</script>
<form name="MyForm">
<input type="text" name="MyText" value="Hell/0 World!" onblur="CheckString(this.value)">
<input type="submit">
</form>
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Sep 6th, 2003, 09:56 PM
#3
Thread Starter
Hyperactive Member
RealisticGraphics, thanks for the code. No need to explain, I see what is going on in it.
Thanks for your help.
-
Sep 6th, 2003, 09:58 PM
#4
Fanatic Member
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|