How can add Phone Number Charecter Validation asp.net mvc web

Harun Ergün 260 Reputation points
2023-01-26T09:07:25.9433333+00:00

Guys I have question

How can Add Phone Number Charecter Validation

For example.. User writing 8 charecter but ı want minimum 10 charecter and maximum 20 charekter how can add ?

Model

User's image

index.cshtml

User's image

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | ASP.NET | ASP.NET API
Developer technologies | ASP.NET | Other
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Viorel 125.7K Reputation points
    2023-01-26T10:29:13.8+00:00

    If you are interested in extending the JavaScript validation, then maybe do it like this:

    if( tel1.length < 10 || tel1.length > 20 )
    {
       . . . show the error . . .
    }
    

    Also check the HTML documentation for modern elements like <input type="tel"...>.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. cristopheB 551 Reputation points
    2023-01-26T09:18:38.24+00:00

    Hello.

    On the field Tel1 for exemple add some annondation like this

    [StringLength(20, MinimumLength=10)]
    public string Tel1 (get; set;)
    

  2. Harun Ergün 260 Reputation points
    2023-01-26T11:19:34.17+00:00

    solution true

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.