PHP to Javascript compare string with characters list -


i have php function compare username $value characters list:

strlen($value) == count(array_intersect(array_map("strtoupper", str_split($value)), str_split("abcdefghijklmnopqrstuvwxyz0123456789_-"))) 

i need obtain similar using jquery. have problems array_intersect() @ moment, can't find similar function.
answer.

stack overflow has questions array intersection in javascript.

you may interested intersection function in underscore.js.

finally, wouldn't easier here use regular expressions? in php, code becomes simple as:

$isvalidusername = preg_match('/^[a-z_\-]+$/i', $value); 

in javascript:

var isvalidusername = (/^[a-z_\-]*$/i).test('hello_world'); 

Comments

Popular posts from this blog

ios - Change Storyboard View using Seague -

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -