c# - Allow only A-I 0-9 and the symbols $# (RegEX) -


i`m working on student project in c#, , want check if string contains following characters:

a-i 0-9 $ #

the original string:

string rawdata ="$a008b20130503c103804d00000000e1022f0080g0128h022i022#"; 

my code follows:

string regexstring = @"^[a-i0-9$#]+$"; regex regex = new regex(regexstring); if (regex.ismatch(rawdata))    {        dataok = true;    }    else        dataok = false; 

what doing wrong?

fixing rawdata/rawdata typo, code works fine. dataok variable becomes true example data, , false if 1 adds other characters string.

judging example data, can improve verification can determinte that:

  • the string starts $
  • the string ends #
  • the strings contains entities consist of single character followed @ least 3 digits

for that, use pattern like:

string regexstring = @"^\$([a-i]\d{3,})+#$"; 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -