473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

at lest 2 character in that and a maximum of 3 characters.

33
I am creating a 6 character alpha numeric sting dynamically

i just want to esure that there is at lest 2 character in that and a maximum of 3 characters.
others will be automatically digits (3-4)

I made a regular expression ie like


^([a-zA-Z]{2,3}[0-9]{3,4})|([0-9]{3,4}[a-zA-Z]{2,3}?)$

but is not matching for 22XX22
here i have 4 digits and 2 letters it must be matching
what to do?

KUTTAN
Jan 31 '09 #1
3 1584
KevinADC
4,059 Expert 2GB
Your description of how the string can be constructed is not very clear so unless you can define the possible permuations better here is a generic way to check such a string:

Expand|Select|Wrap|Line Numbers
  1. my $string = '22XX22';
  2. if ($string =~ /[a-zA-Z]{2,3}/ && $string =~ /^[a-zA-Z0-9]{6}$/) {
  3.    print "$string is good\n";
  4. }
  5. else {
  6.    print "$string is bad\n";
  7. }
  8.  
Jan 31 '09 #2
KUTTAN
33
X88X88 should be matched for the regular expression [a-zA-Z]{2,3}, since there are two characters
but this is not matching
:(
Jan 31 '09 #3
KevinADC
4,059 Expert 2GB
No, it should not match. You don't understand how {n,n} works. It matches if the characters are in sequence, so XX and XXX will match but not X because it is only one character. Here is a solution that will work no matter where the alpha characters are in the string:

Expand|Select|Wrap|Line Numbers
  1. my $string = 'X88X88';
  2. my $alphas = $string =~ tr/a-zA-Z/a-zA-Z/;#counts the number of characters
  3. if (($alphas == 2 || $alphas == 3) && $string =~ /^[a-zA-Z0-9]{6}$/) {
  4.    print "$string is good\n";
  5. }
  6. else {
  7.    print "$string is bad\n";
  8. }
Jan 31 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bruce | last post by:
Hello, This is something that's bothered me for quite a while. Does anyone know why Access has, for so many years, defaulted to 50 characters for the fieldsize value when setting a table...
17
by: Gladiator | last post by:
When I am trying to execute a program from "The C Programming Language" by Dennis Ritchie, I tried to run the following program.I am using Dev++ as a compiler software. The Program is presented...
6
by: @sh | last post by:
Guys, Working on a function to alert the user to too many characters being entered into a text area, I've put together this function so far borrowing bits from resource websites... function...
44
by: Kulgan | last post by:
Hi I am struggling to find definitive information on how IE 5.5, 6 and 7 handle character input (I am happy with the display of text). I have two main questions: 1. Does IE automaticall...
5
toxicpaint
by: toxicpaint | last post by:
Hi, I'm sure there is a really easy way to do this and I'm just being silly, but is there a way that I can get a text box to stop people typing when it hits its maximum character length. I've...
8
by: arnuld | last post by:
i have created a solutions myself. it compiles without any trouble and runs but it prints some strange characters. i am not able to find where is the trouble. ...
17
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
4
by: senthilnathan1985 | last post by:
Hello, i have to check following things in textbox control.I need javascript for this.Can anyone help me..... - be at least 1 character long - contain at least 1 standard alphabetic character...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.