Clean file name php file

0

I'm very clumsy in terms of regular expressions.

I need to clean the name of a file in both the frontEnd and the backEnd that only accepts lowercase letters except the ñ without accents and only numbers and the two types of dashes, spaces replace them with scripts

I have the following expression in the frontEnd

$('#name_folder').on('input', function (e) {
            if (!/^[a-z0-9\-_]+(\s)*$/i.test(this.value)) {
                this.value = this.value.replace(/[^a-z0-9\-_\s]+/,"");              
            }
        }); 
  

I occupy the event in the input and a replace , but it has a bug that   When I write a letter or a digit that does not allow, it erases everything.

I also need to replicate this when on the PHP side, in case this validation is skipped, I can correct it.

    
asked by cignius 09.04.2018 в 23:20
source

0 answers