Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Validate value in a Property?

$
0
0

Should be fairly straight forward I have a property for a phone number and I want to be sure that only the numeric values are "stored"

So lets say we have something like:

private string _phone;

public string Phone {
    get {
        return _phone;
    } set {
        if (IsNumeric(value)) {
            _phone = value;
        } else {
            _phone = StripPhone(value);
        }
    }
}
I believe I've done something similar in VB and it worked, yet not in C#?  IsNumeric and StripPhone are functions.  I can't find any examples that are similar to this so hopefully someone can point me in the right direction.



Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>