0

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.

1 Answer 1

1

try

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

For example

/^[A-Z][a-zA-Z0-9]+/.test("Asd");
Sign up to request clarification or add additional context in comments.

5 Comments

if i replace my regex expression with your regex then alert messege will popup at every time if i enter alphanumeric letters also
@Shafi74 it won't if you enter first character as uppercase.
If I enter first character as lowercase it should be validate
@Shafi74 are you saying that if first character is lowercase then also it is valid? Then you question is not in synch with your comment.
i will give an example if i enter first character as lowercase like aBCD then alert messege should be (First Letter Shoulb Be UpperCase) or automaticaly first character will change like ABCD. Thanq For responding please fulfill my requirement either using regex or any methods

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.