Disallow a path with the file name that contains a non-english characters

Sindibad_123
Sindibad_123 used Ask the Experts™
on
Hi, how to disallow a path with the file name that contains a non-english characters using javascript.

Regards.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Software developer
Commented:
if (/[^a-z\s&'-\.]/gi.test(which.value)) {
alert ("Only alpha characters, spaces, apostrophe, hyphen, full stop and & are valid in this field");

Now that you have allowed spaces, you really need to strip leading spaces and check the field length to prevent just spaces being entered:-

<script type = "text/javascript">
function checkField(which) {
nm = which.value;
nm = nm.replace(/^\s+/,""); // strip leading spaces
if ((/[^a-z\s&'-\.]/gi.test(nm)) || (nm.length == 0)) {
alert ("Only alpha characters, space, apostrophe, hyphen, full stop and & are valid in this field");
which.value = "";
which.focus();
return false;
}
}
</script>

If you want you can refine this further to ensure that the field contains at least 2 alpha characters, thus weeding out ------, &&&&& and ....... (or similar silly entries)


<script type = "text/javascript">
function checkField(which) {
nm = which.value;
nm = nm.replace(/^\s+/,""); // strip leading spaces
nm1 = nm.replace(/[^a-z]/gi,""); // strip non-alpha chars
if ((/[^a-z\s&'-\.]/gi.test(nm)) || (nm.length == 0) || (nm1.length < 2)) {
alert ("Only alpha characters (2 minimum), space, apostrophe, hyphen, full stop and & are valid in this field");
which.value = "";
which.focus();
return false;
}
}
</script>

Author

Commented:
>Now that you have allowed spaces, you really need to strip leading spaces

Thank you, but why I need to strip spaces?!
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

his full sentence reads
<<Now that you have allowed spaces, you really need to strip leading spaces and check the field length to prevent just spaces being entered:>>

Did you tried my solution?

Author

Commented:
>.Did you tried my solution?

No, your links talks about path validation, this is not what I'm talking about.

>Now that you have allowed spaces, you really need to strip leading spaces and check the field length to prevent just spaces being entered

My quest still stands, why I need to remove white spaces from a path and file name?! its allowed in Windows os.
Terry WoodsIT Guru
Most Valuable Expert 2011
Commented:
Windows doesn't allow leading or trailing spaces in filenames, so it makes sense to remove them.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial