How to check if string contains Latin characters only?

前端 未结 6 1835
旧巷少年郎
旧巷少年郎 2021-01-30 12:39

How to check if a string contains [a-zA-Z] characters only?

Example:

var str = \'123z56\';
6条回答
  •  情书的邮戳
    2021-01-30 12:52

    All these answers are correct, but I had to also check if the string contains other characters and Hebrew letters so I simply used:

    if (!str.match(/^[\d]+$/)) {
        //contains other characters as well
    }
    

提交回复
热议问题