How to check if string contains Latin characters only?

前端 未结 6 1697
旧巷少年郎
旧巷少年郎 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:54

    You can use regex:

    /[a-z]/i.test(str);
    

    The i makes the regex case-insensitive. You could also do:

    /[a-z]/.test(str.toLowerCase());
    

提交回复
热议问题