0% found this document useful (0 votes)
91 views

Phone Number Validation - PRF192 - Workshop 6 Question - Contests - HackerRank

The document provides instructions for a coding challenge to validate if a given string representing a phone number is in a valid format. There are two valid formats - (xxx) xxx-xxxx and xxx-xxx-xxxx where x is a digit. The document includes sample inputs and expected outputs to validate phone numbers in both formats and an invalid number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

Phone Number Validation - PRF192 - Workshop 6 Question - Contests - HackerRank

The document provides instructions for a coding challenge to validate if a given string representing a phone number is in a valid format. There are two valid formats - (xxx) xxx-xxxx and xxx-xxx-xxxx where x is a digit. The document includes sample inputs and expected outputs to validate phone numbers in both formats and an invalid number.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

22:05, 26/10/2021 Phone Number Validation | PRF192 - Workshop 6 Question | Contests | HackerRank

NEW
PREPARE CERTIFY COMPETE APPLY  Search  
SE1648_He161883

All Contests

PRF192 - Workshop 6

Phone Number Validation

Phone Number Validation

Problem Submissions Leaderboard Discussions

Given a string representing a phone number, write a program to check whether it is a valid phone number. Suppose that a valid
phone number must appear in one of the following format:

(xxx) xxx-xxxx

xxx-xxx-xxxx

here, x means a digit.

Input Format

One string representing a phone number

Constraints

The length of the given phone number is less than 100

Output Format

If the given phone number is valid, print out "valid". Otherwise, print out "not valid".

Sample Input 0

(031) 456-8823

Sample Output 0

valid

Sample Input 1

031-456-8823

Sample Output 1

valid

Sample Input 2

0314568823

Sample Output 2

https://www.hackerrank.com/contests/prf192-workshop-6/challenges/phone-number-validation 1/2
22:05, 26/10/2021 Phone Number Validation | PRF192 - Workshop 6 Question | Contests | HackerRank

not valid

  

Contest ends in
25 minutes

Submissions:
16
Max Score:
40
Difficulty: Easy

Rate This Challenge:







More

C  

1 ▾#include <stdio.h>
2 #include <string.h>
3 #include <math.h>
4 #include <stdlib.h>
5
6 ▾int main() {
7
8 ▾    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
9 ▾    char s[100];
10    gets(s);
11 ▾    if((s[0] == '(' && s[4] == ')' && s[5] == ' ') ||(s[3] == '-' && s[7] == '-'))
12        printf("valid");
13    else
14        printf("not valid");
15    return 0;
16 }
17

Line: 1
Col: 1

 Upload Code as File


Test against custom input Run Code
Submit Code

Contest Calendar
|
Interview Prep
|
Blog
|
Scoring
|
Environment
|
FAQ
|
About Us
|
Support
|
Careers
|
Terms Of Service
|
Privacy Policy
|
Request a Feature

https://www.hackerrank.com/contests/prf192-workshop-6/challenges/phone-number-validation 2/2

You might also like