PDA

View Full Version : Need help with this regex script



DJ Hands3
Jul 6th, 2009, 05:02 PM
</script>
<script language="Javascript">
function alphaNumericCheck(){
var regex=/^[0-9a-zA-Z]+.((mp3)|(MP3))$/; //^[a-zA-z]+$/
if(regex.test(document.form2.mirror1_url.value)){
return true;
} else {
alert('ERROR: Please rename your uploading file so it ONLY contains letters and numbers and start again by clicking cancel, e.g. my funky - house mix.mp3 should be myfunkyhousemix.mp3 this is to avoid broken streaming and download links!')
document.form2.mirror1_url.value='';
}
}
</script>


Hello I need some help with the above script the one above does work but I need to adjust it slighty,

All I really require is to not accept whitespace and only accept .mp3 .MP3 .zip .ZIP extentsions only with filenames containing no whitespace.

Philip M
Jul 6th, 2009, 07:47 PM
Try this:-


<script type = "text/javascript">

function alphaNumericCheck(){
var urlVal = document.form2.mirror1_url.value;
if (/^[a-z0-9]+\.((mp3)|(zip))$/i.test(urlVal)) {
alert ("OK"); // delete after testing
return true;
}
else {
alert('ERROR: Please rename your uploading file so it ONLY contains letters and numbers and start again by clicking cancel, e.g. my funky - house mix.mp3 should be myfunkyhousemix.mp3 this is to avoid broken streaming and download links!');
document.form2.mirror1_url.value='';
return false;
}
}

</script>


<SCRIPT language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead.