saarsc saarsc - 2 years ago 56
Javascript Question

How to check if a string contain a list if characters which are not in english

I want to valid textbox text. the textbox is for a phone number so, of course, letters and anything other the number I used different kinds of code


$(document).ready(function () {
$("#sub").click(function () {
var regex = /[$%^&*()_+[]{}<>?]אבגדהוזחטיכךלמםנןסעפצקרשת \"/
var bleangth = $('.bphone').val().length;
var eleangth = $('.ephone').val().leangth;
var cbphone = $('.bphone').val();
var cephone = $('.ephone').val();
if (bleangth < 3 || eleangth < 7) {

if (regex.test(cbphone) || regex.test(cephone)) {
else {
alert( "end " + regex.test(cephone) +" start " + regex.test(cbphone));

As you see I entered letters from different language but for some reason the code can't "read" it and return true is there a way maybe to get string split it to array and then use it? or different code or something I need to add/ download

Thank you in advance

Answer Source

If requirement is for only numbers to be input you should be able to use NOT operator ! operator with RegExp /\D/ ; e.g.; !/\D/.test(/*input*/) where true would be result if input is a digit, false if input is not a digit.

An approach using HTML5 <input> element with pattern attribute set to \d+, required attribute; <label> element, CSS :focus, :invalid , adjacent siblings selector +

input + label {

input:focus:invalid + label {
<input type="text" 
       placeholder="Please input digits 0-9"
       required /><label>Invalid input. Please input digits 0-9</label>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download