INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

check string has only a-z0-9

check string has only a-z0-9

(OP)
hello,

Example with [[:alnum:]] I found in post http://www.tek-tips.com/viewthread.cfm?qid=1699291 is not working good in case german letters Ä/ä, Ö/ö, Ü/ü are in a string:

CODE

# echo 243dÜdd|awk '$1 !~ /^[[:alnum:]]+$/ {print "notalnum"}'
# echo 243dÜdd|awk '$1 !~ /^[a-zA-Z0-9]+$/ {print "notalnum"}'
notalnum
# echo 243dÜdd|awk '$1 !~ /^[a-z0-9]+$/ {print "notalnum"}'
notalnum
# echo 243ddd|awk '$1 !~ /^[a-z0-9]+$/ {print "notalnum"}'
# 

I think /^[a-z0-9]+$/ is the best solution in my case if I want to prove there are only digits and/or low letter english characters in string. Am I correct? Are both "green" commands below correct solutions?

What is the meaning of {u=1}{if(u!=1) in the first green command below?
Why the red command does not output the same?

1'st: awk '$1 !~ /^[a-z0-9]+$/{u=1}{if(u!=1){print $0" - only a-z and/or 0-9"}}' input2
2'nd: awk '$1 ~ /^[a-z0-9]+$/{u=1}{if(u=1){print $0" - only a-z and/or 0-9"}}' input2

CODE

# cat input2
9pv8bdm82e8v8ga3
vp4xnbvvgu59ykz8
9uei8zr8dx4kecna
zr7n23hhvmrt7qzf
idxrdpxrkzbzby9b
pexqgf7b3w59m4n6
gjvt9sjtsut4s2dg
fb6vqc7r9ayucmyt
7tkek58cyzfrzs7f
3casnfiwpgq24pt9
nWLheuvjCsZaMK4M
34ZZcf5qVYQhqNsd
sDMW7HGJ9qsU9uqB
wQiZ5nQZMpGCB9q3
LBYSSniZcb4kVsvR
GezLTPunDAzPJpRd
zx6Skn2NP49tv4KC
gJX9gRwtawHskgWj
daCPNCkkFtdBvxMc
FtkwJhqtd7kPmG9R
97RRGD(&9SsPeUDv
SCbAgAxW=-5Ca]Tt
r}F5BL9Uw)}Z]BR*
[+JCKBsbL#z%bNwQ
M9bgcv9X}73ZTaf*
j(L2G=nmAiqx4hJ[
|#D]xW5vkERA|4Jh
=nu]$cJCJ78Xz[4w
aRUW#fNn$x&~)NhE
9Zz?=EYbWp7RLHH$
jNyw(-s&r+}3|)5G
}i*+{hUCVuW=GfA6
kK%dQvnN$jV7+Tza
wyjM8ABmUb(7}EDn
7N95mBJTxMcgy!Pb
TdXmcw*CeixWy}7|
Hhvc2VpQ9y#i[ZU=
RaX4zB(7kQMir2]S
B3u)a=EX?(4t[LF8
}T4?ZbRG+w){%gNF
# awk '$1 !~ /^[a-z0-9]+$/{u=1}{if(u!=1){print $0" - only a-z and/or 0-9"}}' input2
9pv8bdm82e8v8ga3 - only a-z and/or 0-9
vp4xnbvvgu59ykz8 - only a-z and/or 0-9
9uei8zr8dx4kecna - only a-z and/or 0-9
zr7n23hhvmrt7qzf - only a-z and/or 0-9
idxrdpxrkzbzby9b - only a-z and/or 0-9
pexqgf7b3w59m4n6 - only a-z and/or 0-9
gjvt9sjtsut4s2dg - only a-z and/or 0-9
fb6vqc7r9ayucmyt - only a-z and/or 0-9
7tkek58cyzfrzs7f - only a-z and/or 0-9
3casnfiwpgq24pt9 - only a-z and/or 0-9
# awk '$1 !~ /^[a-z0-9]/{u=1}{if(u!=1){print $0" - only a-z and/or 0-9"}}' input2
9pv8bdm82e8v8ga3 - only a-z and/or 0-9
vp4xnbvvgu59ykz8 - only a-z and/or 0-9
9uei8zr8dx4kecna - only a-z and/or 0-9
zr7n23hhvmrt7qzf - only a-z and/or 0-9
idxrdpxrkzbzby9b - only a-z and/or 0-9
pexqgf7b3w59m4n6 - only a-z and/or 0-9
gjvt9sjtsut4s2dg - only a-z and/or 0-9
fb6vqc7r9ayucmyt - only a-z and/or 0-9
7tkek58cyzfrzs7f - only a-z and/or 0-9
3casnfiwpgq24pt9 - only a-z and/or 0-9
nWLheuvjCsZaMK4M - only a-z and/or 0-9
34ZZcf5qVYQhqNsd - only a-z and/or 0-9
sDMW7HGJ9qsU9uqB - only a-z and/or 0-9
wQiZ5nQZMpGCB9q3 - only a-z and/or 0-9
# awk '$1 ~ /^[a-z0-9]+$/{u=0}{if(u!=0){print $0" - only a-z and/or 0-9"}}' input2
# awk '$1 ~ /^[a-z0-9]+$/{u=0}{if(u=0){print $0" - only a-z and/or 0-9"}}' input2
# awk '$1 ~ /^[a-z0-9]+$/{u=1}{if(u=1){print $0" - only a-z and/or 0-9"}}' input2
9pv8bdm82e8v8ga3 - only a-z and/or 0-9
vp4xnbvvgu59ykz8 - only a-z and/or 0-9
9uei8zr8dx4kecna - only a-z and/or 0-9
zr7n23hhvmrt7qzf - only a-z and/or 0-9
idxrdpxrkzbzby9b - only a-z and/or 0-9
pexqgf7b3w59m4n6 - only a-z and/or 0-9
gjvt9sjtsut4s2dg - only a-z and/or 0-9
fb6vqc7r9ayucmyt - only a-z and/or 0-9
7tkek58cyzfrzs7f - only a-z and/or 0-9
3casnfiwpgq24pt9 - only a-z and/or 0-9
nWLheuvjCsZaMK4M - only a-z and/or 0-9
34ZZcf5qVYQhqNsd - only a-z and/or 0-9
sDMW7HGJ9qsU9uqB - only a-z and/or 0-9
wQiZ5nQZMpGCB9q3 - only a-z and/or 0-9
LBYSSniZcb4kVsvR - only a-z and/or 0-9
GezLTPunDAzPJpRd - only a-z and/or 0-9
zx6Skn2NP49tv4KC - only a-z and/or 0-9
gJX9gRwtawHskgWj - only a-z and/or 0-9
daCPNCkkFtdBvxMc - only a-z and/or 0-9
FtkwJhqtd7kPmG9R - only a-z and/or 0-9
97RRGD(&9SsPeUDv - only a-z and/or 0-9
SCbAgAxW=-5Ca]Tt - only a-z and/or 0-9
r}F5BL9Uw)}Z]BR* - only a-z and/or 0-9
[+JCKBsbL#z%bNwQ - only a-z and/or 0-9
M9bgcv9X}73ZTaf* - only a-z and/or 0-9
j(L2G=nmAiqx4hJ[ - only a-z and/or 0-9
|#D]xW5vkERA|4Jh - only a-z and/or 0-9
=nu]$cJCJ78Xz[4w - only a-z and/or 0-9
aRUW#fNn$x&~)NhE - only a-z and/or 0-9
9Zz?=EYbWp7RLHH$ - only a-z and/or 0-9
jNyw(-s&r+}3|)5G - only a-z and/or 0-9
}i*+{hUCVuW=GfA6 - only a-z and/or 0-9
kK%dQvnN$jV7+Tza - only a-z and/or 0-9
wyjM8ABmUb(7}EDn - only a-z and/or 0-9
7N95mBJTxMcgy!Pb - only a-z and/or 0-9
TdXmcw*CeixWy}7| - only a-z and/or 0-9
Hhvc2VpQ9y#i[ZU= - only a-z and/or 0-9
RaX4zB(7kQMir2]S - only a-z and/or 0-9
B3u)a=EX?(4t[LF8 - only a-z and/or 0-9
}T4?ZbRG+w){%gNF - only a-z and/or 0-9
# awk '$1 ~ /^[a-z0-9]+$/{print $0" - only a-z and/or 0-9"}' input2
9pv8bdm82e8v8ga3 - only a-z and/or 0-9
vp4xnbvvgu59ykz8 - only a-z and/or 0-9
9uei8zr8dx4kecna - only a-z and/or 0-9
zr7n23hhvmrt7qzf - only a-z and/or 0-9
idxrdpxrkzbzby9b - only a-z and/or 0-9
pexqgf7b3w59m4n6 - only a-z and/or 0-9
gjvt9sjtsut4s2dg - only a-z and/or 0-9
fb6vqc7r9ayucmyt - only a-z and/or 0-9
7tkek58cyzfrzs7f - only a-z and/or 0-9
3casnfiwpgq24pt9 - only a-z and/or 0-9
# awk '$1 !~ /^[a-z0-9]+$/{u=1}{if(u!=1){print $0" - only a-z and/or 0-9"}else {print $0" - not only a-z and/or 0-9"}}' input2
9pv8bdm82e8v8ga3 - only a-z and/or 0-9
vp4xnbvvgu59ykz8 - only a-z and/or 0-9
9uei8zr8dx4kecna - only a-z and/or 0-9
zr7n23hhvmrt7qzf - only a-z and/or 0-9
idxrdpxrkzbzby9b - only a-z and/or 0-9
pexqgf7b3w59m4n6 - only a-z and/or 0-9
gjvt9sjtsut4s2dg - only a-z and/or 0-9
fb6vqc7r9ayucmyt - only a-z and/or 0-9
7tkek58cyzfrzs7f - only a-z and/or 0-9
3casnfiwpgq24pt9 - only a-z and/or 0-9
nWLheuvjCsZaMK4M - not only a-z and/or 0-9
34ZZcf5qVYQhqNsd - not only a-z and/or 0-9
sDMW7HGJ9qsU9uqB - not only a-z and/or 0-9
wQiZ5nQZMpGCB9q3 - not only a-z and/or 0-9
LBYSSniZcb4kVsvR - not only a-z and/or 0-9
GezLTPunDAzPJpRd - not only a-z and/or 0-9
zx6Skn2NP49tv4KC - not only a-z and/or 0-9
gJX9gRwtawHskgWj - not only a-z and/or 0-9
daCPNCkkFtdBvxMc - not only a-z and/or 0-9
FtkwJhqtd7kPmG9R - not only a-z and/or 0-9
97RRGD(&9SsPeUDv - not only a-z and/or 0-9
SCbAgAxW=-5Ca]Tt - not only a-z and/or 0-9
r}F5BL9Uw)}Z]BR* - not only a-z and/or 0-9
[+JCKBsbL#z%bNwQ - not only a-z and/or 0-9
M9bgcv9X}73ZTaf* - not only a-z and/or 0-9
j(L2G=nmAiqx4hJ[ - not only a-z and/or 0-9
|#D]xW5vkERA|4Jh - not only a-z and/or 0-9
=nu]$cJCJ78Xz[4w - not only a-z and/or 0-9
aRUW#fNn$x&~)NhE - not only a-z and/or 0-9
9Zz?=EYbWp7RLHH$ - not only a-z and/or 0-9
jNyw(-s&r+}3|)5G - not only a-z and/or 0-9
}i*+{hUCVuW=GfA6 - not only a-z and/or 0-9
kK%dQvnN$jV7+Tza - not only a-z and/or 0-9
wyjM8ABmUb(7}EDn - not only a-z and/or 0-9
7N95mBJTxMcgy!Pb - not only a-z and/or 0-9
TdXmcw*CeixWy}7| - not only a-z and/or 0-9
Hhvc2VpQ9y#i[ZU= - not only a-z and/or 0-9
RaX4zB(7kQMir2]S - not only a-z and/or 0-9
B3u)a=EX?(4t[LF8 - not only a-z and/or 0-9
}T4?ZbRG+w){%gNF - not only a-z and/or 0-9
# 



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close