I want to validate if a string is valid ARGB.
E.g. #ffffffff is ARGB 255,255,255,255
How can I validate this using TypeScript and C#?
I want to validate if a string is valid ARGB.
E.g. #ffffffff is ARGB 255,255,255,255
How can I validate this using TypeScript and C#?
For either language, you can use regular expressions to ensure a string matches your expectations. Here are some examples in Typescript and C#.
Typescript
const argbRegex = /^#[0-9a-fA-F]{8}$/;
argbRegex.test("#ffffffff"); // true
argbRegex.test("#gggggggg"); // false
C#
Regex argbRegex = new Regex("^#[0-9a-fA-F]{8}$");
argbRegex.IsMatch("#ffffffff"); // True
argbRegex.IsMatch("#gggggggg"); // False
Since you didn't mention it in your question, there are some things that you might want to consider that I did not cover:
However, if all you need to do is validate the string is strictly in the 8 characters ARGB format, the above examples will work ok.