Mvc validation regular expression only numbers?

后端 未结 3 1875
梦如初夏
梦如初夏 2021-02-14 09:45

I tried the following code for digits-only validation for a contact number validation in Mvc web app.

[RegularExpression(@\"/(^\\(\\d{10})?)$/\", ErrorMessage =          


        
3条回答
  •  后悔当初
    2021-02-14 10:00

    / / is javascript way to build a regular expression literal object. In .NET you should not use it.

    Try the following:

    @"^\((\d{10}?)\)$"
    

    or if you want exactly 10 digits:

    @"^(\d{10})$"
    

提交回复
热议问题