-2

I Just Update my requirement can you please help me,

Required Regex Validation Start two Fixed character and then after First point required alphanumeric characters and second point required Numeric fixed Character.

Example:

  1. if character start with PB then allow 25 character

- Length : additional 25 numbers. - Example : PB12345Ab8901234567890123mM If “PB” then 25 alphanumeric characters. PB+25numbers

  1. if character start with CC then allow 14 character

- Length : additional 14 numbers. - Example : CC012345678901234 If “CC” then 14 numbers. CC+14numbers

Prakash
  • 11
  • 2

1 Answers1

-1

Please try below code

var regExString = "PB0123456789012345678901234";

Regex regex ;

if regExString.startwith("PB"){
    regex = new Regex(@"PB[0-9]{25}$");
}
if regExString.startwith("CC"){
    regex = new Regex(@"CC[0-9]{14}$");
}     

Please let me know the string "PB" and "CC" are fixed or the can be anything.

Piyali Das
  • 54
  • 3
  • Yes, PB and CC is fixed character – Prakash Aug 27 '20 at 08:36
  • You could also *assemble* it as, e.g., `(?:PB|CC)(?:\d{25}|\d{14})$` – Jimi Aug 27 '20 at 09:11
  • What? That *copy/pasted* wrong: `(?:PB\d{25}|CC\d{14})$` – Jimi Aug 27 '20 at 09:27
  • Thanks Piyali Das and Jimi both of your code helpful me. – Prakash Aug 27 '20 at 11:52
  • You are most welcome Prakash – Piyali Das Aug 27 '20 at 12:23
  • your previous answer work for me but need another requirement Piyali Das and Jimi can you please help me again – Prakash Aug 31 '20 at 14:53
  • Prakash, Please explain the requirement in details please. – Piyali Das Aug 31 '20 at 15:29
  • If ‘AB’ enter AB and 25 characters (AB1234567Cb123456B8912Dc567) If ‘CC’ enter CC and 14 numbers (CC02345678902345) – Prakash Sep 01 '20 at 06:23
  • Try this solution: `(?:AB[\da-zA-Z]{25}|CC\d{14})$` If you want to allow other character also, then use `(?:AB[\d\D]{25}|CC\d{14})$` Below are some basic rule: 1. Regular expression for any digit from 0-9: \d 2. Regular expression for any character that not digit define by \d: \D 3. Regular expression to match a range of single lower case character: [a-c] 4. Regular expression to match a range of single upper case character: [A-Z] 5. Regular expression to match a range of single case insencetive character: [a-zA-Z] check https://www.rexegg.com/regex-quickstart.html – Piyali Das Sep 03 '20 at 12:42
  • (?:AB[\da-zA-Z]{25}|CC\d{14})$ i need in this expression add one condition if string not start with AB or CC then it's allow 0 to 100 character. – Prakash Sep 10 '20 at 15:16
  • (?:PB[A-Za-z0-9]{25}|CC\d{14})$ in this expression add ^.{0,100}$ this condition. – Prakash Sep 11 '20 at 06:09