Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/filipe11402/futils-validations

.NET Util to validate brand specific credit card numbers
https://github.com/filipe11402/futils-validations

Last synced: 4 days ago
JSON representation

.NET Util to validate brand specific credit card numbers

Awesome Lists containing this project

README

        

# Credit Card number validation library

Validate your credit card numbers based on their brand using data anotations

---
# How to use

### .NET CLI
```
dotnet add package FUtils.CreditCard.Validations
```

### Nuget
```
Install-Package FUtils.CreditCard.Validations
```

---
## Validate MasterCard credit card
```cs
public class CreditCardModel
{
//choose the desired credit card brand
//in this case MasterCard
[MasterCard]
public string CreditCardNumber { get; set; }
}
```

```cs
public class CreditCardController : Controller
{
//Use your model as the model that get's the data
[HttpPost]
[Route("/")]
public IActionResult MyRoute([FromBody] CreditCardModel myModel)
{
//This will check if the credit card number is valid
//You can then return an error message to your taste
if(ModelState.IsValid)
{
return StatusCode(StatusCodes.400BadRequest);
}

//Apply your logic
//...

return StatusCode(StatusCodes.200OK);
}
}
```