Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] RegEx for validating a file name
- From: rod.coate at falkirkcollege.ac.uk (Rod Coate)
- Subject: [Javascript] RegEx for validating a file name
- Date: Thu May 19 09:55:56 2005
Hi,
I am tring to use a regular expression to validate user input (a file name) on my html using javascript.
What I have tried so far is:
=====================================================
<script type="text/javascript">
function validateFileName(fileName){
var validReg="\W+\.\W{3}$";
var regex= new RegExp(validReg);
return regex.test(fileName);
}
function checkFileName(f){
var fileName=f.value;
if(!validateFileName(fileName)){
alert("file name is not valid");
f.value="";
document.myForm.fileName.focus();
}
}
</script>
<form action="" name="myForm" method="post">
<input type="text" name="fileName" value="" onChange="checkFileName(this);">
</form>
=====================================================
but the regex does not seem to work correctly. What I want is to make sure that fileName is alphanumeric, contains only one . and has three alpha characters after the .
It also should not contain things like \/*?| ect or any spaces.
Is anyone able to help with the regex to get it to work? (I have tried google, but can't find what I am looking for).
Cheers,
Rod.
- Follow-Ups:
- [Javascript] RegEx for validating a file name
- From: Shawn Milo
- [Javascript] RegEx for validating a file name
- Prev by Date: [Javascript] Buttons and Sound in FireFox
- Next by Date: [Javascript] NETSCAPE 7.0 (DISABLE CONTROL-CLICK on LINKS)
- Previous by thread: [Javascript] Buttons and Sound in FireFox
- Next by thread: [Javascript] RegEx for validating a file name
- Index(es):