Patrik Krehák
Patrik Krehák

Reputation: 2683

Return if string has valid characters

I want to make function, that works like Windows' rename function enter image description here.

When you type text and regex is a-zA-Z0-9 then you can type only "alphanumeric" characters. But characters like -, _ or + would be accepted too. Also non-english characters like č š ý ž í á should be accepted too.

Upvotes: 0

Views: 37

Answers (1)

Ali Habibzadeh
Ali Habibzadeh

Reputation: 11577

If you just want to not allow those characters in the bubble then:

function filenameOk(name){
    return !/[\\/:*?<>|]/.test(name);
}

// filenameOk('čšýžíá') --> true

Upvotes: 2

Related Questions