0
char name[50];
int valid;

do{
      valid=1;
      printf("Enter name for Salesman: ");
      fgets(name,50,stdin);
      if(!isalpha(*name)) //it will only scan for the first character of string
      {
          printf("Only alphabet is allowed.\n");
          valid=0;
      }
  }while(valid==0);

I want the whole string doesn't have any numeric input.

2 Answers 2

1

You will have to process the entire string:

int i = 0;
for (i = 0; i < strlen(name) && i < 50; i++) {
  if (!isalpha(name[i])) {
    valid = 0;
    printf("Please only use alphabetic characters!\n");
    break;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Doesn't C language support regular expression like java does ?

so we can do it in java like this :

String test= "Any String even if 1 digit is in between";

Pattern p = Pattern.compile("[0-9]+");

Matcher m = p.matcher(test);

if (m.find())
{               
    System.out.println("Numeric is not allowed");
}

Comments

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.