Regular Expression + Disable removal of String + textbox + Asp.net + VB

I have a texbox that is asking a user to enter as asset number.

the first 4 characters are always the same (UGHS)  I want to disable the user from removing these characters.

I then need the user to enter a minimum of 5 digits at the end of UGHS.  I presume this will be done using regular expressions.  
LVL 7
skiltzAsked:
Who is Participating?
 
McExpCommented:
   <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox1" Mask="\U\G\H\S99999">
    </ajaxToolkit:MaskedEditExtender>
0
 
McExpCommented:
0
 
skiltzAuthor Commented:
Well I can do UGHS\d+ which works pretty well.  Will have a look at masked edit.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
McExpCommented:
are you doing your regex client side?
0
 
skiltzAuthor Commented:
Yes
0
 
McExpCommented:
Forgot, you need to also set ClearMaskOnLostFocus to false

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox1" Mask="\U\G\H\S99999" ClearMaskOnLostFocus="false">
    </ajaxToolkit:MaskedEditExtender>
0
 
skiltzAuthor Commented:
Works great except can't add more than 5 digits..should be minimum of 5 digits..
0
 
McExpCommented:
No Problem, extend the mask (to however digits you need as a max) and use the Validator to check that it is at least 5 digits

    <asp:TextBox ID="TextBox1" runat="server" />

    <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server"
    TargetControlID="TextBox1" Mask="\U\G\H\S9999999999"  />

    <ajaxToolkit:MaskedEditValidator
    ID="MaskedEditValidator1"
    runat="server"
    ControlExtender="MaskedEditExtender1"
    ControlToValidate="TextBox1" IsValidEmpty="False" ValidationExpression="^UGHS\d{5}....."  
    EmptyValueMessage="Enter at least 5 digits"
    InvalidValueMessage="Enter at least 5 digits"
    />
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.