Answers for "check string not having special characters javascript indexof"

3

javascript check if string contains special characters

var email = "[email protected]";
if(email.includes("@")){
  console.log("Email is valid");
}
else{
  console.log("Email is not valid");
}
// includes return boolean, if your string found => true else => false
Posted by: Guest on June-19-2021
0

occurences of special character in a string javascript

// program to check the occurrence of a character

function countString(str, letter) {

    // creating regex 
    const re = new RegExp(letter, 'g');

    // matching the pattern
    const count = str.match(re).length;

    return count;
}

// take input from the user
const string = prompt('Enter a string: ');
const letterToCheck = prompt('Enter a letter to check: ');

//passing parameters and calling the function
const result = countString(string, letterToCheck);

// displaying the result
console.log(result);
Posted by: Guest on February-01-2022

Code answers related to "check string not having special characters javascript indexof"

Code answers related to "Javascript"

Browse Popular Code Answers by Language