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

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,197 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,280 questions
C#
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.
10,288 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
301 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.5K 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