shafi7468
shafi7468

Reputation: 433

Regex Expression validation in javascript

Regex to check the first character is in uppercase and allow only alphanumeric,not allow the special charcter. Thank you Advance

    function checkName(val) {    
    var alpha = document.getElementById(val).value;    
    var filter = /^[a-zA-Z0-9 ]*$/;    
    if (!filter.test(alpha)) {
        alert("Please Enter Alphanumeric Only");
        return false;                                                   
    } 
    return true;   
  }  

i Used This its working properly for checking alphanumeric but for first character uppercase its not working where can i modify my regex expression or any solution.

Upvotes: 0

Views: 36

Answers (1)

gurvinder372
gurvinder372

Reputation: 68393

try

/^[A-Z][a-zA-Z0-9]+/

For example

/^[A-Z][a-zA-Z0-9]+/.test("Asd");

Upvotes: 1

Related Questions