javascript - validation only for type word english or persian or number? -



javascript - validation only for type word english or persian or number? -

how validation type word english language or western farsi or number, each separate in input? not want utilize of plugin.

only type english language -> hello type western farsi -> سلام type number -> 123123

1. english only

var only_english = 'abcdabdkdk', mixed = 'سلامaasdsd'; if (/[^a-za-z]/g.test(only_english)) { alert('"only_english" contains characters other english'); } else { alert('"only_english" contains english language characters'); } if (/[^a-za-z]/g.test(mixed)) { alert('"mixed" contains characters other english'); } else { alert('"mixed" contains english language characters'); }

2. persian only

var only_persian = 'سلام', mixed = 'سلامaasdsd'; if (/[^\u0600-\u06ff]/g.test(only_persian)) { alert('"only_persian" ontains characters other persian'); } else { alert('"only_persian" ontains western farsi characters'); } if (/[^\u0600-\u06ff]/g.test(mixed)) { alert('"mixed" contains characters other persian'); } else { alert('"mixed" contains western farsi characters'); }

3. only numbers

var only_numbers = '12334', mixed = '3124adqad'; if (/[^0-9]/g.test(only_numbers)) { alert('"only_numbers" not contain numbers'); } else { alert('"only_numbers" contains numbers'); } if (/[^0-9]/g.test(mixed)) { alert('"mixed" not contain numbers'); } else { alert('"mixed" contains numbers'); }

javascript jquery-validate jquery

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -